-
February 13th, 2013, 09:12 PM
#1
need help on cpp file
I am suppose to make a program that will output a line for a specific age group,but everytime I execute the exe file it gives me the desired line and also the last line included everytime.Where did I go wrong with it including the last line everytime?
#include <iostream>
using namespace std;
int main()
{
double age;
cout<<"Enter your age:";
cin>>age;
if (0<age && age <6)
cout<< "You are considered a young minor. But, in approximately ___ year(s) you will be able to attend school!"<<endl;
else if (6<=age && age<16)
cout<< "In approximately ___ year(s) you will be able to drive!"<<endl;
else if (16<=age && age<21)
cout<< "In approximately ___ year(s) you will be of legal drinking age."<<endl;
else if (21<= age && age<35)
cout<< "You are of legal drinking age. In approximately ___ year(s) you will be able to run for president!"<<endl;
else if (35<= age && age<120)
cout<< "You are old enough to run for U.S. President."<<endl;
else(age >=120);
cout<< "You are too old to run for U.S. President."<<endl;
}
-
February 14th, 2013, 04:22 AM
#2
Re: need help on cpp file
Originally Posted by trashedsoul
I am suppose to make a program that will output a line for a specific age group,but everytime I execute the exe file it gives me the desired line and also the last line included everytime.Where did I go wrong with it including the last line everytime?
#include <iostream>
using namespace std;
int main()
{
double age;
cout<<"Enter your age:";
cin>>age;
if (0<age && age <6)
cout<< "You are considered a young minor. But, in approximately ___ year(s) you will be able to attend school!"<<endl;
else if (6<=age && age<16)
cout<< "In approximately ___ year(s) you will be able to drive!"<<endl;
else if (16<=age && age<21)
cout<< "In approximately ___ year(s) you will be of legal drinking age."<<endl;
else if (21<= age && age<35)
cout<< "You are of legal drinking age. In approximately ___ year(s) you will be able to run for president!"<<endl;
else if (35<= age && age<120)
cout<< "You are old enough to run for U.S. President."<<endl;
else(age >=120);
cout<< "You are too old to run for U.S. President."<<endl;
}
Your last else expression is the reason!
It should be either
Code:
else
cout<< "You are too old to run for U.S. President."<<endl;
or
Code:
else if(age >=120);
cout<< "You are too old to run for U.S. President."<<endl;
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|