write a function called grade that takes an integer argument ( between 0 and 100
ID: 3620946 • Letter: W
Question
write a function called grade that takes an integer argument ( between 0 and 100 and return one character based on the input integer number , and return charracter Z otherwiseDefine a function after called so function prototype needed.
write a program to read in one integer at a time and pass that integer to function grade to determine the character grade
use do loop to read five integer values in main function .Print the score and grade after calling function
calculate the average score for all five input score
Explanation / Answer
please rate - thanks
you didn't specify when the Z was to be returned or what letter grade for each number so I did standard grades, as my message to you indicated, and returned Z if the numbers were not within 0 and 100, but I included all numbers in the average
message me if any changes needed
#include <iostream>
using namespace std;
char grade(int);
int main()
{int i,n,tot=0;
double average;
char ch;
for(i=0;i<5;i++)
{cout<<"Enter score "<<i+1<<": ";
cin>>n;
ch=grade(n);
cout<<"grade: "<<n<<" letter grade: "<<ch<<endl;
tot+=n;
}
average=tot/5.;
cout<<"Your average is "<<average<<endl;
system("pause");
}
char grade(int n)
{if(n>100||n<0)
return 'Z';
else if(n>=90)
return 'A';
else if(n>=80)
return 'B';
else if(n>=70)
return 'C';
else if(n>=60)
return 'D';
else
return 'F';
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.