*** stuck with the output of this program, the math is not right. doesnt matter
ID: 3722478 • Letter: #
Question
*** stuck with the output of this program, the math is not right. doesnt matter the numbers i put i always get a grade A. can you help me fix the math part. Rest of the program works ****
#include <iostream>
using namespace std;
int main()
{
double quiz1;
double quiz2;
double midterm;
double finals;
double avg;
char Grade;
cout << "Enter the score of quiz1: ";
cin >>quiz1;
cout <<endl;
cout << "Enter the score of quiz2: ";
cin >> quiz2;
cout<<endl;
cout<< "Enter the score of the mid-term exam: ";
cin>>midterm;
cout<<endl;
cout<< "Enter score of the final exam: ";
cin>>finals;
cout<<endl;
cout<<endl;
avg = ((quiz1 + quiz2) + (midterm * 0.25) + (finals * 0.50));
if (avg >= 90)
{
Grade = 'A';
}
else if (avg >= 80 && avg <= 89)
{
Grade = 'B';
}
else if (avg >= 70 && avg <=79)
{
Grade = 'C';
}
else if (avg >=60 && avg <=69)
{
Grade = 'D';
}
else if (avg > -1 && avg <=59)
{
Grade = 'F';
}
cout<< "Score of quiz1: " << quiz1;
cout<<endl;
cout<< "Score of quiz2: " << quiz2;
cout<<endl;
cout<<"Score of mid-term exam: "<<midterm;
cout<<endl;
cout<<"Score of final exam: "<<finals;
cout<<endl;
cout<<"Score for the entire course is " <<avg;
cout<<endl;
cout<<endl;
switch (Grade)
{
case 'A':
cout<< "The Grade is: "<< Grade;
break;
case 'B':
cout<< "The Grade is: "<< Grade;
break;
case 'C':
cout<< "The Grade is: "<< Grade;
break;
case 'D':
cout<< "The Grade is: "<< Grade;
break;
case 'F':
cout<< "The Grade is: "<< Grade;
break;
default:
cout << "Undefined value! Make sure it's a value from 0-100!";
break;
}
return 0;
}
Explanation / Answer
Here Problem was with avg calculation , Here is the changed avg math:
avg = (((quiz1 + quiz2) * 0.25) + (midterm * 0.25) + (finals * 0.50));
Here is the correct Program:
#include <iostream>
using namespace std;
int main()
{
double quiz1;
double quiz2;
double midterm;
double finals;
double avg;
char Grade;
cout << "Enter the score of quiz1: ";
cin >>quiz1;
cout <<endl;
cout << "Enter the score of quiz2: ";
cin >> quiz2;
cout<<endl;
cout<< "Enter the score of the mid-term exam: ";
cin>>midterm;
cout<<endl;
cout<< "Enter score of the final exam: ";
cin>>finals;
cout<<endl;
cout<<endl;
avg = (((quiz1 + quiz2) * 0.25) + (midterm * 0.25) + (finals * 0.50));
cout<<"avg"<<avg;
if (avg >= 90)
{
Grade = 'A';
}
else if (avg >= 80 && avg <= 89)
{
Grade = 'B';
}
else if (avg >= 70 && avg <=79)
{
Grade = 'C';
}
else if (avg >=60 && avg <=69)
{
Grade = 'D';
}
else if (avg > -1 && avg <=59)
{
Grade = 'F';
}
cout<< "Score of quiz1: " << quiz1;
cout<<endl;
cout<< "Score of quiz2: " << quiz2;
cout<<endl;
cout<<"Score of mid-term exam: "<<midterm;
cout<<endl;
cout<<"Score of final exam: "<<finals;
cout<<endl;
cout<<"Score for the entire course is " <<avg;
cout<<endl;
cout<<endl;
switch (Grade)
{
case 'A':
cout<< "The Grade is: "<< Grade;
break;
case 'B':
cout<< "The Grade is: "<< Grade;
break;
case 'C':
cout<< "The Grade is: "<< Grade;
break;
case 'D':
cout<< "The Grade is: "<< Grade;
break;
case 'F':
cout<< "The Grade is: "<< Grade;
break;
default:
cout << "Undefined value! Make sure it's a value from 0-100!";
break;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.