Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Today assignment , find the errors in this code and fixed them. Please I need he

ID: 3855489 • Letter: T

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.

#include <iostream>

#include <cstring>

#include <iomanip>

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;

}

Explanation / Answer

Values already declared in switch case no need of intialization at the time of program start.Please change the below code

strcpy(msg, "Excellent!");

strcpy(msg, "Good job!");
strcpy(msg, "You've passed!");
strcpy(msg, "Need to put down that video Game!");

Instaed of strcpy(),we can directly assign the values to variables.

Need better declartion for to assign values to grade variable.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote