using namespace std;
char userName ;
cout << " Hello! my name is kevin\n What is you first name? \n";
cin >> userName;
cout << "Hello there " << userName << " what an handsome name!\n So how old are you? \n";
cin >> a;
cout << "oh so you are \n" << a << endl;
cout << "How old do you think i am? \n";
cin >> b;
cout << "Thats Correct ! You guessed my age rigth! 21 \n";
cout << "So we are " << (a + b) << " years old together\n";
cout << "Sadly you did not guess my age rigth! please start over. \n";
cout << "But i calculated that we would be " << (a + b) << "if i was" << b << "years old";
cout << "Lets get to know eachother\n" << endl;
Does anyone understand what am trying to do? its simple i know but am new to this, and i cant seem to figure out the if / else statment, and sometime it calculates wrong please help anyone
Problem with SIMPLE code(am noob)
Post a Reply
|Oldest Newest Rating|
· January 17, 2016
You haven't written the if conditional correctly.
It should go like this:
You want to compare the user input 'a'. I.e Age.
Also I dint understand your 'second' function.
What is it for?
According to me remove that void second(); at the top and at the bottom after return statement.
Hope that helps
· January 13, 2016
you make 2 mistake
you should () instead of 
and, inside () , there should be a comparasion
for your case, it should be if(b==21)
you should watch bucky video about if else statement
this is the summary
Used in many types of software including music players, video games, and many large scale applications.
|Bucky Roberts Administrator|