66 909
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #29927 in C++ for Emily Johnson

Question #29927
Create an program that allows the user to input an age in years and then displays one of the following responses. You program should be able to figure out how many years to display in some of the responses.

My code is here below. What can I do to improve it?


#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

int main()
{
int userAge;
cout << "Please enter userAge " << endl;

if (0 < age && age < 6);
cout << "You are considered a young minor. In approximately" << 6 - userAge << "year(s) you will be able to attend school!"; endl;
else if (age < 16)
cout << "In approximately" << 16 - userAge << "years you will be able to drive!"; endl;
Expert's answer
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

int main()
{
& &
cout << "Please enter userAge " << endl;

int userAge;
cin>>userAge;

if (0 < userAge && userAge < 6)
{
cout << "You are considered a young minor. In approximately " <<
6 - userAge <<
" year(s) you will be able to attend school!"<<
endl;
}
else if (userAge < 16)
{
cout << "In approximately " <<
16 - userAge <<
" year(s) you will be able to drive!"<<
endl;
}
else
{
cout<<"You are able to drive!"<<endl;
}

cin.get();//suspend console, optional.
& &
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions