I cant do it but its in the tutorial
I keep trying lesson 2:If statements in C++ programming in my complier but it doesnt come out like it says it should. Here it is:
Code:
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please input your age: "; // I input my age which is 13
cin>> age;
cin.ignore();
if ( age < 100 ) {
cout<<"You are pretty young!\n";
}
else if ( age == 100 ) {
cout<<"You are old\n";
}
else {
cout<<"You are really old\n";
}
cin.get();
}
And all that comes out of it is 13 and not You are pretty young like the tutorial says it is suppose to what do I do could you help me plz!!!
well it worked fine for me
I just added a "for" loop for testing three diffrent ages
13, 100 and 120.
Code:
int main(void)
{
int age;
int i;
for ( i = 0 ; i < 3 ; ++i )
{
cout<<"Please input your age: "; // I input my age which is 13
cin>> age;
cin.ignore();
if ( age < 100 ) {
cout<<"You are pretty young!\n";
}
else if ( age == 100 ) {
cout<<"You are old\n";
}
else {
cout<<"You are really old\n";
}
}
cin.get();
system("PAUSE");
return EXIT_SUCCESS;
}
the output I got :
Please input your age: 13
You are pretty young!
Please input your age: 100
You are old
Please input your age: 120
You are really old
Press any key to continue . . .
Well here is my full code
The take for every warning your compiler is giving you.
Code:
#include <iostream>
using namespace std;
int main(void)
{
int age;
int i;
for ( i = 0 ; i < 3 ; ++i )
{
cout<<"Please input your age: "; // I input my age which is 13
cin>> age;
cin.ignore();
if ( age < 100 ) {
cout<<"You are pretty young!\n";
}
else if ( age == 100 ) {
cout<<"You are old\n";
}
else {
cout<<"You are really old\n";
}
}
cin.get();
return EXIT_SUCCESS;
}
PS my compiler is bloodshed 4.9.9.2
Search for bloodshed in this site and you find where to download it. ( In my opinion it is very poor. the debgur wont work ... etc)