Write a program based on the example code provide below to accomplish: 1. Create
ID: 3665339 • Letter: W
Question
Write a program based on the example code provide below to accomplish:
1. Create integer variable grade, ask user input the value of grade.
2. Assign a char variable named “coursegrade” based on input value, ‘A’(90-100), ‘B’(80-89), ‘C’(70-79), ‘D’(60-69) and ‘F’(0-59).
3. Use switch function to output the following sentence based on coursegrade A: an A – excellent work B: you got a B – good work C: earning a C is satisfactory D: while D is passing, there is a problem F: you failed – better luck next time
4. Assign a bool variable named “stop” with while function, if user input ‘0’, the program will end; if user input ‘1’, the program will continue.
example:
Example code:
#include <iostream>
using namespace std;
int main()
{
int grade; cout <<"input your grade"<<endl; cin>>grade;
//Assign coursegrade based on input grade
//Switch coursegrade for output return 0;
}
#include <iostream>
using namespace std;
int main ()
{
bool stop=true;
while (stop==true)
{
cout<<"contrinue"<<endl;
cin>>stop; } cout<<"thanks for using"<<endl; return 0;
}
Explanation / Answer
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int grade;
char coursegrade;
bool stop();
cout<<" Enter your grade= ";
cin>>grade;
switch(grade/10)
{
case 10 : coursegrade='A-Excellent Grade';
break;
case 9 : coursegrade='A-Excellent Grade';
break;
case 8 : coursegrade='B-Good Work';
break;
case 7 : coursegrade='C-Satisfactory';
break;
case 6 : coursegrade='D-Passed';
break;
case 5 : coursegrade='F-Failed';
break;
default : coursegrade='F-Failed';
}
cout<<" Your coursegrade is = "<<coursegrade<<endl;
cout << "Do you want to try again? (y/n) " ;
cin >> stop ;
getch();
return 0;
}
bool stop()
{
int answer;
cout << "Do you want to Continue? (y/n)";
cin >> answer;
if (answer == 'y' || answer == 'Y')
return 1;
if (answer == 'n' || answer == 'N')
return 0;
else
cout << "Please enter a valid response";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.