Question
Today assignment , find the errors in this code and fixed them. Please I need help with find the errors and how ro fixed them.
Today assignment , find the errors in this code and fixed them. Please I need help with find the errors and how ro fixed them.
#include
#include
#include
using namespace std;
const int MAX_CHAR = 100;
const int MIN_A = 90;
const int MIN_B = 80;
const int MIN_C = 70;
double getAvg();
char determineGrade(double);
void printMsg(char grade);
int main()
{
double score;
char grade;
char msg[MAX_CHAR];
strcpy(msg, "Excellent!");
strcpy(msg, "Good job!");
strcpy(msg, "You've passed!");
strcpy(msg, "Need to put down that video Game!");
score = getAvg();
grade = determineGrade(score);
printMsg(grade);
return 0;
}
double getAvg()
{
double finalAvg;
cout << "Please enter your final average: ";
cin >> finalAvg;
while(!cin)
{
cin.clear();
cin.ignore(MAX_CHAR, ' ');
cout << "input has to be numerical!" << endl;
cin >> finalAvg;
}
cin.ignore(MAX_CHAR, ' ');
return finalAvg;
}
char determineGrade(double finalAvg)
{
char grade = 'F';
if(finalAvg >= MIN_A)
{
grade = 'A';
}
else if(finalAvg >= MIN_B)
{
grade = 'B';
}
else if(finalAvg >= MIN_C);
{
grade = 'C';
}
return grade;
}
void printMsg(char grade)
{
char msg[MAX_CHAR];
switch(grade)
{
case 'A':
strcpy(msg, "Excellent!");
break;
case 'B':
strcpy(msg, "Good job!");
break;
case 'C':
strcpy(msg, "You've passed!");
break;
default:
strcpy(msg, "Need to put down that video game!");
break;
}
cout << msg << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started