Answer to Question #168207 in C++ for sara

Question #168207

Write a program to check if a person is eligible for a driving license. There are 2

conditions that must be met. The person should be over 18 years old and they should have

passed the driving test. Create a int variable for the age of the person and a variable of your

choice to indicate if the user has passed/failed the test. Get these values from the user. If

the person is eligible, your program must display "User can drive!" otherwise display "User

cannot drive!"


1
Expert's answer
2021-03-02T08:03:04-0500
#include <iostream>
#include <string>
using namespace std;
int main(){
    int age;
    string answer;
    cout<<"Please enter user age: \n";
    cin>>age;
    if(age>18){
        cout<<"\nHas user passed the driving test? (yes/no)\n";
        cin>>answer;
        if(answer == "yes"){
            cout<<"User can drive!";
        }
        else cout<<"User cannot drive!";
    }
    else cout<<"User cannot drive!";
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS