I wrote a swtich statement and am wondering if its possible to put a loop into this code and if i could how would i do it? what i want is, if the grade chosen is not a,b or c, than i want it to repeat until they put that char in.
#include <iostream>
#include <string>
using namespace std;
int main ( )
{
char grade, Keep_going;
cout << "enter your grade based on how you think you performed???\n";
cin >> grade;
do
{
switch (grade)
{
case 'A':
case 'a':
cout << "Wow. You probably did get an A\n";
cout << "great job this semester\n";
break;
case 'B':
case 'b':
cout << "that is pretty good. However you coulda done better\n";
break;
case 'c':
case 'C':
cout << "you failed\n";
break;
default:
cout << "that is not an option. please pick\n";
cout << " between a,b,c.";
}
#include <iostream>
#include <string>
usingnamespace std;
int main ( )
{
char grade, Keep_going;
do
{
cout << "enter your grade based on how you think you performed???\n";
cin >> grade;
switch (grade)
{
case'A':
case'a':
cout << "Wow. You probably did get an A\n";
cout << "great job this semester\n";
break;
case'B':
case'b':
cout << "that is pretty good. However you coulda done better\n";
break;
case'c':
case'C':
cout << "you failed\n";
break;
default:
cout << "that is not an option. please pick\n";
cout << " between a,b,c.";
}
}while(/*In Here!*/);//<<---Insert your condition here
cin >> Keep_going;
return 0;
}
It currently cannot compile. After you insert your condition, then maybe...
#include <iostream>
#include <string>
usingnamespace std;
int main ( )
{
char grade, Keep_going;
cout << "enter your grade based on how you think you performed???\n";
cin >> grade;
while(getch())
{
switch (grade)
{
case'A':
case'a':
cout << "Wow. You probably did get an A\n";
cout << "great job this semester\n";
break;
case'B':
case'b':
cout << "that is pretty good. However you coulda done better\n";
break;
case'c':
case'C':
cout << "you failed\n";
break;
default:
cout << "that is not an option. please pick\n";
cout << " between a,b,c.";
}
cout << "enter your grade based on how you think you performed???\n";
cin >> grade;
}
return 0;