Answer to Question #24668 in C++ for alfred lontoc
Question #24668
5. Due to poor results of your prelim examination, your teacher decides to increase each student’s grade by 5. Get all the grades and compute for the new grade. If the original grade exceeds 90, the grade remains as such. (grade.cpp)
Requirements:
Function for the input.
Function for the formula/process together with the output.
Sample Run:
Name: Eugerico
Grade: 80
Your new grade is 85
Do you want to enter another record [y/n]? y
Name: Laurence
Grade: 91
Your grade is still 91.
Do you want to enter another record [y/n]? y
Name: Ana
Grade: 76
Your new grade is 81
Do you want to enter another record [y/n]? n
Exit
Requirements:
Function for the input.
Function for the formula/process together with the output.
Sample Run:
Name: Eugerico
Grade: 80
Your new grade is 85
Do you want to enter another record [y/n]? y
Name: Laurence
Grade: 91
Your grade is still 91.
Do you want to enter another record [y/n]? y
Name: Ana
Grade: 76
Your new grade is 81
Do you want to enter another record [y/n]? n
Exit
Expert's answer
# include <iostream>
# include <string >
using namespace std;
int main(){
string name;
int d=0;
char ans;
while (true){
cout<<"Name:";
cin.ignore();
getline(cin,name,'\n');
cout<<"Grade:";
cin>>d;
cout<<"Your new grade:";
if (d<90) cout<<d+5<<endl;
if (90<=d<100) cout<<d<<endl;
cout<<"Continue?";
cin>> ans;
if (ans=='n') break;
}
system("PAUSE");
return 0;
}
# include <string >
using namespace std;
int main(){
string name;
int d=0;
char ans;
while (true){
cout<<"Name:";
cin.ignore();
getline(cin,name,'\n');
cout<<"Grade:";
cin>>d;
cout<<"Your new grade:";
if (d<90) cout<<d+5<<endl;
if (90<=d<100) cout<<d<<endl;
cout<<"Continue?";
cin>> ans;
if (ans=='n') break;
}
system("PAUSE");
return 0;
}
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment