Question

In: Computer Science

I can not get the summary report to show in the output it just keeps running...

I can not get the summary report to show in the output it just keeps running after i enter the names, scores, and then / /. Can someone help me I am using codeblocks but I might be able to figure out even if you use another IDE>

This is my code

#include <iostream>

using namespace std;

int main()
{
string name;
double score =0;
int totalStudents = 0;
int A=0,B=0,C=0,D=0,F=0;
cout << "Enter student name" << endl;
cin >> name;

while (name!="//"){
cout << "Enter student score" << endl;
cin >> score;
if(score>=90){
A++;
cout<<name<<" "<<score<<" A"<<endl;
}
else if(score>=80&&score<90){
B++;
cout<<name<<" "<<score<<" B"<<endl;
}
else if(score>=70&&score<80){
C++;
cout<<name<<" "<<score<<" C"<<endl;
}
else if(score>=60&&score<70){
D++;
cout<<name<<" "<<score<<" D"<<endl;
}
else if (score>=0&&score<60) {
F++;
cout<<name<<" "<<score<<" F"<<endl;
}
cout << "Enter student name" << endl;
cin >> name;
totalStudents++;
}
cout << "Enter student name" << endl;
cin >> name;
cout << "Summary Report" << endl;
cout << "Total Students count " << totalStudents << endl;
cout << "A student count " << A << endl;
cout << "B student count " << B << endl;
cout << "C student count " << C << endl;
cout << "D student " << D << endl;
cout << "F students " << F << endl;
return 0;
}


This was the question

Topics

Loops

while Statement

Description

Write a program that computes the letter grades of students in a class from knowing their scores in a test. A student test score varies from 0 to 100. For a student, the program first asks the student’s name and the student’s test score. Then, it displays the student name, the test score and the letter grade. It repeats this process for each student. The user indicates the end of student data by entering two consecutive forward slashes ( // ) when asked for the student name. At the end, the program displays a summary report including the following:

·       The total number of students.

·       The total number of students receiving grade “A”.

·       The total number of students receiving grade “B”.

·       The total number of students receiving grade “C”.

·       The total number of students receiving grade “D”.

·       The total number of students receiving grade “F”.

The program calculates a student's the letter grade from the student's test score as follows:

A is 90 to 100 points

B is 80 to 89 points

C is 70 to 79 points

D is 60 to 69 points

F is 0 to 59 points.

Requirements

Do this exercise using a While statement and an If/Else If statement.

Testing

For turning in the assignment, perform the test run below using the input data shown

Test Run (User input is shown in bold).

Enter Student Name

Alan

Enter Student Score

75

Alan 75 C

Enter Student Name

Bob

Enter Student Score:

90

Bob 90 A

Enter Student Name

Cathy

Enter Student Score

80

Cathy 80 B

Enter Student Name

Dave

Enter Student Score:

55

Dave 55 F

Enter Student Name

Eve

Enter Student Score

85

Eve 85 B

Enter Student Name

//

Summary Report

Total Students count 5

A student count 1

B student count: 2

C student count 1

D student 0

F students 1

Sample Code

string name;

double score;

//Initias setup

cout << "Enter student name" << endl;

cin >> name;

//Test

while (name != "//")

{

    cout << "Enter student score" << endl;

    cin >> score;

    //more code here

    //Update setup

    out << "Enter student name" << endl;

    cin >> name;

}

//display summary report

Solutions

Expert Solution

The problem is not with the IDE their is a small mistake in your code due to which your code is not able to even reach the lines of code that print the summary report. Let's discuss it in detail. As soon as you enter // you will go out of your while loop and after while loop you have lines:-

cout << "Enter student name" << endl;
cin >> name;

So these lines would ask the user to input name again and these lines would stop lines of code that print the summary report.And you would never be able to print the summary report. Hence remove these lines from your code before this line cout << "Summary Report" << endl; And you will be able to print the summary report

Let's DryRun Your code

Enter Student Name

Alan

Enter Student Score

75

Alan 75 C

Enter Student Name

Bob

Enter Student Score:

90

Bob 90 A

Enter Student Name

Cathy

Enter Student Score

80

Cathy 80 B

Enter Student Name

Dave

Enter Student Score:

55

Dave 55 F

Enter Student Name

Eve

Enter Student Score

85

Eve 85 B

Enter Student Name

//

Enter Student Name(Instead of Summary Report)

Now as soon as you enter // you will go out of your while loop and after while loop you have lines:-

cout << "Enter student name" << endl;
cin >> name;

So these lines would ask the user to input name again and these lines would stop lines of code that print the summary report.And you would never be able to print the summary report. Hence remove these lines from your code before this line cout << "Summary Report" << endl; And you will be able to print the summary report. Use the code as follows:-

#include <iostream>

using namespace std;

int main()
{
string name;
double score =0;
int totalStudents = 0;
int A=0,B=0,C=0,D=0,F=0;
cout << "Enter student name" << endl;
cin >> name;

while (name!="//"){
cout << "Enter student score" << endl;
cin >> score;
if(score>=90){
A++;
cout<<name<<" "<<score<<" A"<<endl;
}
else if(score>=80&&score<90){
B++;
cout<<name<<" "<<score<<" B"<<endl;
}
else if(score>=70&&score<80){
C++;
cout<<name<<" "<<score<<" C"<<endl;
}
else if(score>=60&&score<70){
D++;
cout<<name<<" "<<score<<" D"<<endl;
}
else if (score>=0&&score<60) {
F++;
cout<<name<<" "<<score<<" F"<<endl;
}
cout << "Enter student name" << endl;
cin >> name;
totalStudents++;
}
cout << "Summary Report" << endl;
cout << "Total Students count " << totalStudents << endl;
cout << "A student count " << A << endl;
cout << "B student count " << B << endl;
cout << "C student count " << C << endl;
cout << "D student " << D << endl;
cout << "F students " << F << endl;
return 0;
}

This would print the summary report.


Related Solutions

Can I get a summary of this article in details and what is your position and...
Can I get a summary of this article in details and what is your position and opinion on the topic of the Nicaragua channel? Nicaragua's dream of building an interoceanic canal fades in the face of uncertainty over the 50 billion dollars needed to finance it and China's decision to open relations with its rival in Panama, according to analysts. The project "has been totally de-funded because it did not meet the reliability requirements it needed" for its execution, the...
My Java program keeps "running." I know I need to close a "loop" but I can't...
My Java program keeps "running." I know I need to close a "loop" but I can't find it. I'm learning how to code. This is confusing for me. import java.util.Scanner; import java.util.ArrayList; public class SteppingStone4_Loops {    public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String recipeName = ""; ArrayList<String> ingredientList = new ArrayList(); String newIngredient = ""; boolean addMoreIngredients = true; System.out.println("Please enter the recipe name: "); recipeName = scnr.nextLine();    do {    System.out.println("Would you...
"Please can I get a feedback on this discussion post below" Can I get it in...
"Please can I get a feedback on this discussion post below" Can I get it in 2 hours please .thanks Tesla is a company recently in the news for a conflict of interest between the SEC and the CEO Elon Musk due to an interest to bring the company private by the CEO who shared on Twitter his short term plans. Production issues, a number of layoffs and the increasing demand for the electric vehicles were expressed by the CEO...
You have just been pulled over for running a red light. In an attempt to get...
You have just been pulled over for running a red light. In an attempt to get out of the resulting traffic fine, you tell the police officer that as you drove toward the traffic signal the red light was Doppler shifted so much that it appeared green to you. “Ok,” says the officer, “then I’ll ticket you for speeding. The fine is $1 for every 1km/h over the posted speed limit of 50 km/h.” How big is your fine? Use...
I have the following python code. I get the following message when running it using a...
I have the following python code. I get the following message when running it using a test script which I cannot send here: while textstring[iterator].isspace(): # loop until we get other than space character IndexError: string index out of range. Please find out why and correct the code. def createWords(textstrings): createdWords = [] # empty list for textstring in textstrings: # iterate through each string in trxtstrings iterator = 0 begin = iterator # new begin variable while (iterator <...
can you please do this question? i need the result asap. show the output as well...
can you please do this question? i need the result asap. show the output as well Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1:...
please just show a small hint on how I can include these component on the design...
please just show a small hint on how I can include these component on the design point please please I know it might take your time and I am really sorry for that also I appreciate  the time and effort you will put onto this thank you very much Clear description and/or sketch of product Energy Thermodynamicso Matter/Materialso Radiation Electrochemistry Waves A private space company wants to be the first to start mining in space. This could be the moon, asteroids...
please just show a small hint on how I can include these component on the design...
please just show a small hint on how I can include these component on the design point please please I know it might take your time and I am really sorry for that also I appreciate  the time and effort you will put onto this thank you very much Clear description and/or sketch of product Energy Thermodynamicso Matter/Materialso Radiation Electrochemistry Waves A private space company wants to be the first to start mining in space. This could be the moon, asteroids...
Please show all work so that i can get a better understanding A.) Estimate ΔG°rxn for...
Please show all work so that i can get a better understanding A.) Estimate ΔG°rxn for the following reaction at 449.0 K. CH2O(g) + 2 H2(g) → CH4(g) + H2O(g) ΔH°= -94.9 kJ; ΔS°= -224.2 J/K a. +12.9 kJ b. -4.2 kJ c. +5.8 kJ d. -101 kJ e. +2.4 kJ B.) Which of the following statements is TRUE? a. Endothermic processes decrease the entropy of the surroundings, at constant T and P. b. Exothermic processes are always spontaneous. c....
I want to write an executive summary of this whole report and list of illustrations for...
I want to write an executive summary of this whole report and list of illustrations for COMMUNICATION MANAGEMENT. "Regina man ordered by SGI to turn in 'MAGAUSA' licence plate" Rod Kletchko believes surrendering his “MAGAUSA” vanity plate to Saskatchewan Government Insurance (SGI) would be the equivalent of selling his soul for 30 pieces of silver. The plate, which is a reference to President Donald Trump’s “Make America Great Again” campaign slogan, was approved by SGI and put on Kletchko’s Mercedes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT