Losing my mind (while loop)
Jan 20, 2015 at 2:33am UTC
This is array and loop practice and I cant seem to figure out what is going wrong. I have everything working in my while loop until I introduced the int pref as an input. It will not repeat the question and spazzes out. As soon as I take out everything below the int everything works again. I tried modifying the while loop and tried using a switch instead of another if else for the int. I'm completely lost. Can someone please help?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
const string name[5] = {"Wimp Macho" , "Raki Rhodes" , "Celia Laiter" , "Hoppy Hipman" , "Pat Hand" };
const string title[5] = {"Programmer 1" , "Programmer 2" , "Programmer 3" , "Programmer 4" , "Programmer 5" };
const string bop[5] = {"Mac" , "Lightning" , "Bloop" , "Meep" , "Merp" };
int pref;
char choice;
while (choice != 'q' )
{
cout << "choice:" ;
cin >> choice;
if (choice == 'a' )
cout << name[0] << endl
<< name[1] << endl
<< name[2] << endl
<< name[3] << endl
<< name[4] << endl;
else if (choice == 'b' )
cout << title[0] << endl
<< title[1] << endl
<< title[2] << endl
<< title[3] << endl
<< title[4] << endl;
else if (choice == 'c' )
cout << bop[0] << endl
<< bop[1] << endl
<< bop[2] << endl
<< bop[3] << endl
<< bop[4] << endl;
else if (choice == 'd' )
cout << "Please enter a preference number: " << endl
<< "0 for full name" << endl
<< "1 for title" << endl
<< "2 for BOP name" << endl;
cin >> pref; // Right here is where I'm lost
switch (pref)
{
case '0' :
cout << name[0] << endl
<< name[1] << endl
<< name[2] << endl
<< name[3] << endl
<< name[4] << endl;
break ;
case '1' :
cout << title[0] << endl
<< title[1] << endl
<< title[2] << endl
<< title[3] << endl
<< title[4] << endl;
break ;
case '2' :
cout << bop[0] << endl
<< bop[1] << endl
<< bop[2] << endl
<< bop[3] << endl
<< bop[4]
<< endl;
break ;
}
}
system("PAUSE" );
return EXIT_SUCCESS;
}
Jan 20, 2015 at 2:45am UTC
Topic archived. No new replies allowed.