Question

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

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, '\n');

cout << "input has to be numerical!" << endl;

cin >> finalAvg;

}

cin.ignore(MAX_CHAR, '\n');

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;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
Today assignment , find the errors in this code and fixed them. Please I need help...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi there! I need to fix the errors that this code is giving me and also...

    Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...

  • In C++ please! *Do not use any other library functions(like strlen) than the one posted(<cstddef>) in the code below!* /** CS 150 C-Strings Follow the instructions on your handout to complete t...

    In C++ please! *Do not use any other library functions(like strlen) than the one posted(<cstddef>) in the code below!* /** CS 150 C-Strings Follow the instructions on your handout to complete the requested function. You may not use ANY library functions or include any headers, except for <cstddef> for size_t. */ #include <cstddef> // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// ///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE /////////////////////// // These are OK after...

  • I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs ca...

    I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs can be found at compile time, while others are found at run time. Access the UserMenu.cpp code file (in the zip file in Start Here) and use debugging practices and the debugger in Visual Studio to find each bug. Fix the bug and write a comment in the code giving a description of how you found the...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • Could use some help with this, Instructions: You will need to add an input statement for...

    Could use some help with this, Instructions: You will need to add an input statement for the grade variable to this code. Also add a for loop so that you can enter more than one grade. Code the for loop so that at least 7 grades can be entered. #include <iostream> #include <string> using namespace std; void main() {      char grade;           for (int x = 0; x < 7; x++)      {            cout << "Enter a...

  • Overload the output stream operator << and the assignment operator =. Any time cout << task;...

    Overload the output stream operator << and the assignment operator =. Any time cout << task; is used the code should output a task, any time task1 = task2 is copied there must be a deep copy if there are pointers. Use the operators in the following code as suggested above. DO NOT simply overload them! Do so on the following code: //Project 4 Main function #include "functions.h" #include <stdlib.h> #include <stdio.h> //main int main(){    TaskList column("tasks.txt");    char...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT