Skipping Over Initial Prompt (Do/While)
Feb 14, 2020 at 10:51pm UTC
At the end I give the user the option to rerun the program or exit it. I set up a do/while loop and it sort of works except it prompts straight away the name and id i.e. it skips over the name input a user can give.
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
string name, idNumber, gradeLetter;
int grade;
char answer;
do
{
cout<< "••••••••••••••••••••••••••••••••••••••••••" <<endl
<<"\tWelcome to Grade Estimation Program\n"
<< "••••••••••••••••••••••••••••••••••••••••••" <<endl<<endl
<<"Please Enter your Name (LastName,FirstName): " ;
getline(cin, name);
cout<<"\nPlease Enter you 7 Digit ID: " ; //prompting for id
cin>>idNumber;
while (idNumber.length()!=7) {
cout<<"\nPlease Enter you 7 Digit ID: " ;
cin>>idNumber;
}
for (int grade = 0; grade <= 0 || grade >100;){
if (grade <= 0 || grade > 100) {
cout<<"\nPlease Enter a Score Between 0 and 100: " ;
cin>>grade;
}
if (grade >=90){
gradeLetter= "A+" ;
}
else if (grade >=85 && grade < 90){
gradeLetter= "A" ;
}
else if (grade >=80 && grade < 85){
gradeLetter= "A-" ;
}
else if (grade >=70 && grade < 80){
gradeLetter= "B" ;
}
else if (grade >=60 && grade < 70){
gradeLetter= "C" ;
}
else if (grade <60){
gradeLetter= "F" ;
}
if (grade>0 && grade<101) {
cout<<"\nBased on the " << grade <<" " <<name<<"(" << idNumber <<")" <<" will likely get " <<gradeLetter<<endl;
}
cout<<"\nWould you like to exit the program?(y/n): " ;
cin>>answer;
}
} while (answer=='n' || answer=='N' );
cout<<"\nThank you for using the Grade Estimation Program!" <<endl;
Feb 15, 2020 at 1:39am UTC
Feb 15, 2020 at 3:42am UTC
Worked thanks!
Topic archived. No new replies allowed.