Question

In: Computer Science

In the PDF file that will contain your screen shots, explain what is wrong with the...

In the PDF file that will contain your screen shots, explain what is wrong with the code below. Do not just state thing like “line 3 should come after line 7,” you must explain why it needs to be changed. This shows that you are fully understanding what we are going over.

// This program uses a switch-case statement to assign a

// letter grade (A, B, C, D, or F) to a numeric test score.

#include <iostream>

using namespace std;

int main()

{

double testScore;

cout<< "Enter your test score and I will tell you\n";

cout<<"the letter grade you earned: ";

cin>> testScore;

switch (testScore)

{

case (testScore < 60.0):

cout << "Your grade is F. \n";

break;

case (testScore < 70.0):

cout << "Your grade is D. \n";

break;

case (testScore < 80.0):

cout << "Your grade is C. \n";

break;

case (testScore < 90.0):

cout << "Your grade is B. \n";

break;

case (testScore < 100.0):

cout << "Your grade is A. \n";

break;

default:

cout << "That score isn't valid\n";

return 0;

}

Solutions

Expert Solution

Here we are using the 5 cases in the switch case but our scores will be around 1-100
so we can't assign the proper grade using these 5 case statements
so we need to divide score with 10 than we will get like 9,8,7,6,5 using case blocks to assign the correct grade:

Another issue:
in case labeles we have written conditions which means these values always 0 or 1 as we have used < > operators
which will return 0 or 1 so we have only 2 cases here
case 0:
case 1:
if we get anything other than these values default case will executes and prints This score isn't va;id

Correct Program:

#include <iostream>

using namespace std;

int main(){

double testScore;

cout<< "Enter your test score and I will tell you\n";

cout<<"the letter grade you earned: ";

cin>> testScore;

int g=testScore/10;

switch (g)

{

case 5:

case 4:

case 3:

case 2:

case 1:

case 0:


cout << "Your grade is F. \n";

break;

case 6:

cout << "Your grade is D. \n";

break;

case 7:

cout << "Your grade is C. \n";

break;

case 8:

cout << "Your grade is B. \n";

break;

case 9:

cout << "Your grade is A. \n";

break;

default:

cout << "That score isn't valid\n";

return 0;

}

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Marielab1 input your age and display what your age would be next year. submit screen shots...
Marielab1 input your age and display what your age would be next year. submit screen shots from Marie. im 24 and going to be 25 next year.
Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file....
Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18    List as Stack """ File: pyStackPostfix.py Author: JD """ # 5 7 + 6 2 -  * = 48 print("Postfix Calculator\n") stack = []              # Empty stack...
Run the following ANOVA analysis in excel and interpret your findings. Upload your screen shots of...
Run the following ANOVA analysis in excel and interpret your findings. Upload your screen shots of the steps you took in running the analysis in excel. Treatment 1 Treatment 2 Treatment 3 0 1 6 1 4 5 0 1 8 3 2 5
Run the following ANOVA analysis in excel and interpret your findings. Upload your screen shots of...
Run the following ANOVA analysis in excel and interpret your findings. Upload your screen shots of the steps you took in running the analysis in excel. Treatment 1 Treatment 2 Treatment 3 0 1 6 1 4 5 0 1 8 3 2 5
SHOW SCREEN SHOTS OF THE INPUT AND OUTPUT AS WELL AS THE RESULTS PROGRAMMING IN PERL...
SHOW SCREEN SHOTS OF THE INPUT AND OUTPUT AS WELL AS THE RESULTS PROGRAMMING IN PERL Task 2: Variables 2.1 Scalar Variables A scalar is a single unit of data. That data might be an integer number, floating point, a character, a string, a paragraph, or an entire web page. Simply saying it could be anything, but only a single thing. #!/usr/bin/perl $age = 35; # An integer assignment $name = "Gary Mann"; # A string $salary = 5445.50; #...
What is the output from the following program? Explain your results. file:///Users/brianabernal/Downloads/Question%201.pdf int val = 20;...
What is the output from the following program? Explain your results. file:///Users/brianabernal/Downloads/Question%201.pdf int val = 20; int func1() {     int val = 5;     return val; } int func2() {     return val; } int main() {     // (1)     cout << func1() << endl;     // (2)     cout << func2() << endl; }
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
Solve problems using Minitab. Show evidence that they used the program by putting screen shots of...
Solve problems using Minitab. Show evidence that they used the program by putting screen shots of the results. Will give good rating. Exercises: 1. Among the 120 applicants for a job, only 80 are qualified. If 5 of these applicants are selected at random for an interview, answer the following: to. Identify the random process b. Define a variable c. Associate the random variable with a distribution and its parameters Solve the following questions using Minitab: d. Find the probability...
Solve problems using Minitab. Show evidence that they used the program by putting screen shots of...
Solve problems using Minitab. Show evidence that they used the program by putting screen shots of the results. Will give good rating 2. On a certain cruise, there are, on average, 3 traffic accidents each month. Answer the following: to. Identify the random process b. Define a variable c. Associate the random variable with a distribution and its parameters Solve the following questions using Minitab: d. Find the probability that in a period of 2 months exactly 4 accidents will...
Run the commands used for following tasks and paste the screen shots here: a) Search/find a...
Run the commands used for following tasks and paste the screen shots here: a) Search/find a specified word in a file and display all the lines containing that word. b) List all the files and directories in the current directory (including the hidden files). c) Change to the root directory / and show a complete long listing of it. d) Append the output of file1 to file2. [1 Mark] e) Count how many lines, words and characters in file1. f)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT