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!"
#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;
}
Comments
Leave a comment