Program to compute average with letter grade Write a program to ask the user to
ID: 3923149 • Letter: P
Question
Program to compute average with letter grade
Write a program to ask the user to enter three integer test scores (0 to 100) and to compute and display his numeric average rounded to the nearest whole number ( use set precision(0) <<fixed; ) and his letter grade. The letter grade is assigned as follows:
If his average on the three tests is
less than 60 the letter grade is F
60 or more but less than 70 the letter grade is D
70 or more but less than 80 the letter grade is C
80 or more but less 90 the letter grade is B
90 or more the letter grade is A
Run and test your program for different test scores and check that it computes the correct average and letter grade. Submit your program for each of the letter grades.
i have // printing the students' grades based on their marks
#include <iostream> // if or else
#include <iomanip> // For set precision(0)
#include <cmath>
#include <string.h>
using namespace std;
int main (void)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout<< setprecision(2);
double grade ;
int F = 0 < 60 ; // if grade less than 60 then grade = F
int marks = round(grade) ;
cout <<" Enter Student grade: " << endl ;
cin >> grade;
if (grade <= 60)
cout << "Student grade = F " << endl ;
else if ( 60 >= grade)
cout <<" Student grade = D" << endl ;
else if ( 70 >= grade)
cout <<" Student grade = c" << endl ;
else if ( 80 >= grade)
cout << "Student grade = B"<< endl ;
else if (90 >= grade)
cout << "Student grade = A" << endl ;
else if ( grade >= 90 )
cout << "Student grade is an A" <<endl ;
}
not all grades are showing up
Explanation / Answer
Java code Correct and Commented:
#include <iostream> // if or else
#include <iomanip> // For set precision(0)
#include <cmath>
#include <string.h>
using namespace std;
int main (void)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout<< setprecision(2);
double grade ;
int score[3];
for(int i=0;i<3;i++){
cout<<"Enter score:"<<endl;
cin>>score[i];
if(score[i] < 0 or score[i]>100){
i--;
printf("Try again ");
}
}
grade = round((score[0]+score[1]+score[2])/3.0);
//int F = 0 < 60 ; // if grade less than 60 then grade = F
int marks = round(grade) ;
cout <<" Enter Student grade: " <<marks << endl ;
// cin >> grade;
if (grade < 60) //less than 60 the letter grade is F
cout << "Student grade = F " << endl ;
else if ( 60 >= grade || grade <70)//60 or more but less 70 the letter grade is D
cout <<" Student grade = D" << endl ;
else if ( 70 >= grade || grade <80) //70 or more but less 80 the letter grade is C
cout <<" Student grade = C" << endl ;
else if ( 80 >= grade || grade <90)//80 or more but less 90 the letter grade is B
cout << "Student grade = B"<< endl ;
else if (90 >= grade) //90 or more the letter grade is A
cout << "Student grade = A" << endl ;
}
output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.