Refer to Prelude's comments concerning std::istream::sync() in Simple C++ help for a beginer?Originally Posted by msh
Refer to Prelude's comments concerning std::istream::sync() in Simple C++ help for a beginer?Originally Posted by msh
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks!
So what that does is: "from input buffer, extract and discard the number of characters that correspond to the maximum possible value of type streamsize, e.g. the maximum number of characters that can be placed in the buffer, OR extract and discard all character up until and including the first '\n' that is encountered, whichever comes first". Did I get that about right?Code:cin.ignore(numeric_limits<streamsize>::max(), '\n');
Elegant!
Thanks, laserlight!
May I suggest using a do while loop?
Code:#include <iostream> using namespace std; int main() { int HottestGirl = 0; cout << "Who is the hottest girl?\n"; cout << "1)Claudia Lynx\n"; cout << "2)Megan Fox\n"; cout << "3)Audrina Patridge\n"; cout << "\n"; //------------------------------------------------------------------------------------------------------------------------// START // do { // Do While - cin >> HottestGirl; // Input if (HottestGirl == 1) { // Set Case If cout << "\nClaudia Lynx is the hottest girl!\n\n"; } else if (HottestGirl == 2) { // Set Case If cout << "\nMegan Fox is the hottest girl!\n\n"; } else if (HottestGirl == 3) { // Set Case If cout << "\nAudrina Patridge is the hottest girl!\n\n"; } else { // If none above then do cout << "Invalid Selection\n\n"; } } while (HottestGirl == 0); // Do the above while HottestGirl equals 0 }
hmm... I understand that except for the last part where it says:
What is this there for?Code:} while (HottestGirl == 0);
Also, one thing this doesn't do is display "Selection: " before the user inputting the selection. Is there a way to fix this or no? It's not that it's so important, the program means nothing, I am just trying to learn
Last edited by PersianStyle; 07-13-2009 at 01:14 AM.