Find the errors // Program gets student name and scores on 4 tests // Program co
ID: 3634980 • Letter: F
Question
Find the errors// Program gets student name and scores on 4 tests
// Program computes student average and deermines letter grade
// Higher than 90 is an A, higher than 80 is a B, and so on
start
string name
num score
num NUM_TESTS = 4
num NUM_RANGES = 5
num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0
string GRADES[NUM_RANGES] = "A", "B", "C", "D", "F"
num total
num average
num sub
input name
while not eof
sub = 0
while sub < NUM_TESTS
input score
total = total + score
endwhile
average = total / NUM_TESTS
while average < RANGES[sub]
sub = sub + 1
endwhile
letterGrade = GRADES[total]
output name, letterGrade
input name
endwhile
stop
Explanation / Answer
Dear,
start
string name
num score
num NUM_TESTS = 4
num NUM_RANGES = 5
num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0
string GRADES[NUM_RANGES] = "A", "B", "C", "D", "F"
//Error:Total is declared not initialized .Gives warning
num total
num average
num sub
input name
while not eof
//Error:sub is declaread and initialized but in while loop it is to increment otherwise
//infinite loop occurs
sub = 0
while sub < NUM_TESTS
input score
//Error:total is declared not initialized .Gives warning
total = total + score
endwhile
average = total / NUM_TESTS
//Error:sub is incremented but used anywhere in the program
while average < RANGES[sub]
sub = sub + 1
endwhile
//Error :sub should be zero befor using in while loop
//Error:GRADES[total] gives nothing to letter grade
Error:sub is there instead of total
letterGrade = GRADES[total]
output name, letterGrade
input name
endwhile
stop
//Here is the complete code in cpluplus
#include<iostream>
#include<string>
using namespace std;
int main()
{
string name;
int score;
const int NUM_TESTS = 4;
const int NUM_RANGES = 5;
int RANGES[NUM_RANGES] = {90, 80, 70, 60, 0};
string GRADES[NUM_RANGES] = {"A", "B", "C", "D", "F"};
int total=0;
float average;
int sub=0;
string letterGrade;
cout<<"Enter name";
cin>>name;
while (sub < NUM_TESTS)
{
cout<<"input score";
cin>>score;
total = total + score;
sub++;
}
average = total / NUM_TESTS;
sub=0;
while (average < RANGES[sub])
{
sub = sub + 1;
}
letterGrade = GRADES[sub];
cout<<"Name"<<" Grade"<<endl;
cout<<name<<letterGrade<<endl;
system("pause");
return 0;
}
Hope this would helpful to you..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.