It's okay. It's a very easy mistake for a person new to C++ to make.
It's okay. It's a very easy mistake for a person new to C++ to make.
This code will never execute. You might want to put the else back in there like you originally had it.Code:if (false) { cout << "Way off"; }Code:else { cout << "Way off"; }
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
OK i got it, thanks all!!!!!!
Code:#include <iostream> using namespace std; int main() { int nunb; cout << "Number:"; cin>> nunb; cin.ignore(); if ( nunb == 20 ){ cout << "You read my mind!"; } else { cout << "Way off"; } cin.get(); }
Verbal Irony >>
"I love english homework!" When really nobody like english homework.
-Mrs. Jennifer Lenz (English Teacher)
Or you could put:
You might want to put a loop in there to give the user multiple guesses:Code:if(nunb!=20) { cout<<"Way off!"; }
Code:#include <iostream> using namespace std; int main() { int nunb; bool guess = false; while(guess!=true){ cout << "Number:"; cin>> nunb; cin.ignore(); if ( nunb == 20 ){ cout << "You read my mind!"; guess = true; } if (nunb!=20) { cout << "Way off"<<endl; } } cin.get(); }
No offense, but some of this doesn't make any sense.Code:#include <iostream> using namespace std; int main() { int nunb; cout << "Number:"; cin>> nunb; cin.ignore(); if ( nunb == 20 ){ cout << "You read my mind!"; } if (false) { cout << "Way off"; } cin.get(); }
This statement will NEVER be evaluated. "false" will NEVER evaluate to true and therefore the contents of the if statement will never be executed.Code:if (false) { cout << "Way off"; }
Try this:
else {
cout << "Way off";
}
-Edit-
Sorry about that, I was slow to respond! Old news - move along, nothing to see here