Hello
I was messing around with Microsoft Visual C++ 2008 Express.
I am new to programming and am trying to learn C++
So here is a simple program I made:
At first, I had the 14th line say: while(HottestGirl=1||2||3||4)Code:#include <iostream> using namespace std; int main() { int HottestGirl=1; cout << "Who is the hottest girl?\n"; cout << "1)Claudia Lynx\n"; cout << "2)Megan Fox\n"; cout << "3)Audrina Patridge\n"; cout << "\n"; while(HottestGirl=1) { cout << "Selection:"; cin >> HottestGirl; switch (HottestGirl) { case 1: cout << "Claudia Lynx is the hottest girl!\n\n"; break; case 2: cout << "Megan Fox is the hottest girl!\n\n"; break; case 3: cout << "Audrina Patridge is the hottest girl!\n\n"; break; default: cout << "Invalid Selection\n\n"; HottestGirl=4; break; } } cin.ignore(); cin.get(); }
Therefore, no matter what number the user enters, it will still go in a loop and ask for Selection again.
But then I changed it to: while(HottestGirl=1)
Just to see what happens
The problem is, it still goes in a loop and asks for the selection! Why is this?
Shouldn't it only loop when the user enters 1 for the variable HottestGirl?
I also have another minor question if anyone would like to help
I was going along with the tutorial and it tells me to put cin.ignore(); after having the user input a value and to also have cin.get(); at the end of the program so i can see the results of the program. Could someone explain this a little bit more for me please. I mean I kinda understand how the cin.ignore(); removes the enter and the cin.get(); waits for the user to press enter, but its still kinda bothering me, I don't really get it.
Also, are there any other ways to be able to see the results of the program without it just running the code then auto closing. I think I saw someone you can do like System Pause or something a long time ago.
Thanks for any help in advance!



LinkBack URL
About LinkBacks




