iccaros Posted May 15, 2005 Report Share Posted May 15, 2005 ok I need to know why my while loop is not working.. (it ask for input untill -1 is entered but never does the rest of the loop)#include <iostream>#include <cstdlib>#include <iomanip>using namespace std;//function prototypevoid clear_screen (void);int promptUser (const string& );//main functionint main (){ // local variables int userInput, holder; const int array_size= 9, poll_size=10; //setup arrays int salary [array_size] = {200,300,400,500,600,700,800,900,1000}; int Polldata [poll_size] = {0}; // clear screen clear_screen(); //main loop of program while (( userInput = promptUser ( "Enter Salary or -1 to quit: ")) != -1 );{ holder = userInput / 100; cout << holder << endl; ++Polldata[holder]; } clear_screen(); for ( int x =1; x <= 9; x++){ cout << setw (4) << salary [x-1] << setw (10) << " " << setw (10) << Polldata[x] << endl; } return 0;}//clear screen functionvoid clear_screen(){ #if defined WIN32 system ("cls"); #elif defined UNIX system ("clear"); #endif }//check function for correct input typeint promptUser (const string& s){ while (true) { int snumber; cout << s << flush; cin >> snumber; if (cin.fail()) { cerr << "invalid input \n"; cin.clear(); cin.ignore(); } else return snumber; }} Quote Link to post Share on other sites
jcl Posted May 15, 2005 Report Share Posted May 15, 2005 (edited) while (( userInput = Â promptUser ( "Enter Salary or -1 to quit: ")) != -1 ); Â Â <-- stray semicolon Edited May 15, 2005 by jcl Quote Link to post Share on other sites
shanenin Posted May 15, 2005 Report Share Posted May 15, 2005 those damn stray semicolins :-) Quote Link to post Share on other sites
iccaros Posted May 15, 2005 Author Report Share Posted May 15, 2005 those damn stray semicolins :-) my thought too.. Quote Link to post Share on other sites
iccaros Posted May 15, 2005 Author Report Share Posted May 15, 2005 while (( userInput = promptUser ( "Enter Salary or -1 to quit: ")) != -1 ); <-- stray semicolon thank you.. I was messing with this all the way untill 3 am before just going to bead adn hopeing somesome would show me what is wrong.. now I can do my homework as I understand how to input things in the array.. your the king.. should be Linux and programing expert. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.