Please help me solve this...
Mar 15, 2012 at 4:12am UTC
Hi my question is when I run the program it is asking what the score was for a student and after each score it asks 'more?'and you have to type 'y' or 'n' to continue. Well whatever I press it doesn't stop whether its 'n' or 'm'. My other question is how do I make the program quit if I press anything else other than a number when its asking for a score?
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 79 80 81 82 83 84 85
#include <iostream>
#include <string>
int main()
{
using namespace std;
char ans, more;
void FirstName();
void LastName();
const int SIZE = 10;
float scores[SIZE];
float total = 0;
void FirstName();
{
string fName;
do
{
cout << "First name: " ;
getline(cin, fName);
}
while (fName == "" );
}
void LastName();
{
string lName;
do
{
cout << "Last name: " ;
getline(cin, lName);
}
while (lName == "" );
}
int i;
for (int i = 0; i < SIZE; i++)
{
cout << "Score " << i + 1 << ": " ;
cin >> scores[i];
cout<<"More? :" ;
cin>>more;
}
if (more == 'y' || more == 'Y' )
{
cin>>scores[i];
}
if (more == 'n' || more == 'N' )
{
cout<<"end" ;
}
else
{
cout<<"end" ;
}
for (int i = 0; i < SIZE; i++)
{
total += scores[i];
}
if (more == 'y' || more == 'Y' || more == 'n' || more == 'N' )
{
cout<<"end" <<endl;
}
else
{
cout<<"end" ;
}
return 0;
}
Mar 15, 2012 at 4:31am UTC
delete lines 54 and 55 and make appropriate adjustments to remainder of if clauses
Mar 15, 2012 at 5:00am UTC
i would do it like this
1 2 3 4 5
while (more != 'n' ){
//code here
cout<<"more?" ;
cin>> more;
}
see if that helps
Last edited on Mar 15, 2012 at 5:00am UTC
Topic archived. No new replies allowed.