Question
Hi, I'm making a program that calculates grade by using Terminal. Here's what I've got. -------------------------------------- #include using namespace std; const int MAX_CHAR = 100;
Hi, I'm making a program that calculates grade by using Terminal.
Here's what I've got.
--------------------------------------
#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;
score = getAvg();
grade = determinGrade(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 determinGrade(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;
}
------------------------------------------
And I typed the command "g++ -Wall -g app.cpp -o Lab2" to check if it works well, then I found some error.
It says,
-----------------------------------------------
app.cpp: In function int main():
app.cpp:19:29: error: determinGrade was not declared in this scope
grade = determinGrade(score);
^
app.cpp: In function char determinGrade(double):
app.cpp:52:7: warning: this if clause does not guard... [-Wmisleading-indentation]
else if(finalAvg >= MIN_C);
^~
app.cpp:53:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the if
{
^
app.cpp: In function void printMsg(char):
app.cpp:65:28: error: strcpy was not declared in this scope
strcpy(msg, "Excellent!");
^
--------------------------------------------
Can you list all of bugs, both syntax and semantic, that you have found and fixed?
you need to use gdb to find the semantic bug as well.
Thanks.
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