Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 4, Problem 35RQE

Each of the following program segments has errors. Find as many as you can.

A)

cout << "Enter your 3 test scores and I will ";

<< "average them:";

int scorel, score2, score3,

cin >> scorel >> score2 >> score3;

double average = (scorel + score2 + score3) / 3.0;

if (average = 100);

perfectScore = true; // Set the flag variable

cout << "Your average is " << average << endl;

bool perfectScore;

if (perfectScore);

cout << "Congratulations!\n";

cout << "That's a perfect score.\n";

cout << "You deserve a pat on the back!\n";

B)

double num1, num2, quotient;

cout << "Enter a number: ";

cin  >> num1;

cout << "Enter another number: ";

cin  >> num2;

if (num2 == 0)

   cout << "Division by zero is not possible.\ n";

   cout << "Please run the program again";

   cout << "and enter a number besides zero.\n";

else

   quotient = num1 / num2;

   cout << "The quotient of " << num1 <<

   cout << " divided by " << num2 << " is ";

   cout << quotient << endl;

C)

int testScore;

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

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

cin  >> testScore;

if (testScore < 60)

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

else if (testScore < 70)

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

else if (testScore < 80)

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

else if (testScore < 90)

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

else

     cout << "That is not a valid score.\n";

else if (testScore <= 100)

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

D)

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";

  case (testScore < 70.0):

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

  case (testScore < 80.0) :

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

  case (testScore < 90.0):

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

  case (testScore <= 100.0):

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

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

}

Blurred answer
Students have asked these similar questions
Assignment Write a program that tracks how much steps the user walks in total in a day and reports if the daily target is reached or not. The program will keep reading double values, each representing steps walked during an individual activity within a day (stepsWalked) until either the user enters a negative value or the daily target of 5000 steps is met. If the user enters a negative number, the program should print total steps walked as a double. Otherwise, if the target is exactly reached, the program should simply print "Target is reached", finally if the target is surpassed the program should print the text "Target is surpassed by", followed by the excess amount above the target as a double, and finally printing the text "steps". NOTE: You MUST use a repetitive statement in this question. NOTE: Each stepsWalked value will be given as a non-negative value. You do NOT need to check this. Input Output Answer assignment 3000 1300 500 2305.2 Target is surpassed by 2105.2 steps 450…
Program Requirements This program should add numbers 1 through 9 one a time, via a button click, display the result, and allow the user to Clear the total to zero. Your Starter Codeworks for numbers 1 through 3.  Give it a try, push the buttons, to see what it does. Extending Structured Programs is Easy In this assignment, you use existing code to: identify the patterns in a program modify the patterns in order to extend the functionality of the program Your Task for this Assignment Requirements: Extend this program to create the 6 more HTML buttons and 6 more Javascript functions.   Software Development Best Practice: Incremental Development Do not program all your code at once like you were editing some essay.  Making a big mess and then trying to patch it up all one once... is a nightmare. Add one button and its function Test it Repeat with the next button Pattern One: HTML Button Add your HTML code where the highlighted area is in the image below.  Copy an existing button, and…
MATLAB QUESTION - As of 2018, the population of "A city" is 646 thousand and the population of "B city" is 269 thousand. While the population of "A city" decreases by 7.1% every year, the population of "B city" increases by 12.9%. According to this information, write a program that calculates the year in which the population of "B city" passed the population of "A city".

Chapter 4 Solutions

Starting Out with C++: Early Objects (9th Edition)

Ch. 4.2 - Although the following code segments are...Ch. 4.3 - Write an if/else statement that assigns 0.10 to...Ch. 4.3 - Write an if / else statement that assigns 1 to x...Ch. 4.3 - Write an if /else statement that assigns .10 to...Ch. 4.3 - True or false: The following if / else statements...Ch. 4.3 - Will the if / else statement shown on the right...Ch. 4.4 - What will the following program segment display?...Ch. 4.4 - The following program is used in a bookstore to...Ch. 4.4 - Write an if/else if statement that carries out the...Ch. 4.4 - Write an if/else if statement that performs the...Ch. 4.6 - If you execute the following code, what will it...Ch. 4.6 - If you execute the following code, what will it...Ch. 4.7 - Prob. 4.23CPCh. 4.7 - If a = 2, b = 4, and c = 6, indicate whether each...Ch. 4.7 - If a = 2, b = 4, and c = 6, is the following...Ch. 4.7 - Rewrite the following using the ! operator so that...Ch. 4.9 - Write an if statement that prints the message The...Ch. 4.9 - Write an if statement that prints the message The...Ch. 4.9 - Find and fix the errors in the following code...Ch. 4.10 - Prob. 4.30CPCh. 4.10 - Indicate whether each of the following relational...Ch. 4.10 - Prob. 4.32CPCh. 4.10 - Indicate whether each of these character testing...Ch. 4.11 - Rewrite the following if / else statements as...Ch. 4.11 - Rewrite the following conditional expressions as...Ch. 4.11 - Prob. 4.36CPCh. 4.12 - Explain why you cannot convert the following i...Ch. 4.12 - What is wrong with the following switch statement?...Ch. 4.12 - What will the following program segment display?...Ch. 4.12 - Complete the following program segment by writing...Ch. 4.12 - Rewrite the following program segment using a...Ch. 4.13 - Prob. 4.42CPCh. 4.13 - Follow the instructions to complete the following...Ch. 4 - An expression using the greater-than, less-than,...Ch. 4 - Prob. 2RQECh. 4 - The if statement regards an expression with the...Ch. 4 - For an if statement to conditionally execute a...Ch. 4 - In an if / else statement, the if part executes...Ch. 4 - The trailing else in an if / else if statement has...Ch. 4 - If the subexpression on the left of the logical...Ch. 4 - If the subexpression on the left of the || logical...Ch. 4 - The ____ logical operator has higher precedence...Ch. 4 - Logical operators have _____ precedence than...Ch. 4 - The _____ logical operator works best when testing...Ch. 4 - The _____ logical operator works best when testing...Ch. 4 - A variable with _____ scope is only visible when...Ch. 4 - The expression that is tested by a switch...Ch. 4 - A program will fall through to the following case...Ch. 4 - Prob. 16RQECh. 4 - Write an if statement that assigns 100 to x when y...Ch. 4 - Write an if/else statement that assigns 0 to x...Ch. 4 - Write an if / else statement that prints Excellent...Ch. 4 - Write an if statement that sets the variable hours...Ch. 4 - Convert the following conditional expression into...Ch. 4 - Convert the following if/else if statement into a...Ch. 4 - Assume the variables x = 5, y = 6, and z = 8....Ch. 4 - Assume the variables x = 5, y = 6, and z = 8....Ch. 4 - Write a C++ statement that prints the message The...Ch. 4 - Prob. 26RQECh. 4 - Write a C++ statement that prints the message The...Ch. 4 - Prob. 28RQECh. 4 - Using the following chart, write a C++ statement...Ch. 4 - Write one or more C++ statements that assign the...Ch. 4 - The following statement should determine if x is...Ch. 4 - The following statement should determine if count...Ch. 4 - The following statement should determine if count...Ch. 4 - The following statement should determine if x has...Ch. 4 - Each of the following program segments has errors....Ch. 4 - Sometimes either a switch statement or an if /else...Ch. 4 - Minimum / Maximum Write a program that asks the...Ch. 4 - Roman Numeral Converter Write a program that asks...Ch. 4 - Magic Dates The date June 10, 1960, is special...Ch. 4 - Areas of Rectangles The area of a rectangle is the...Ch. 4 - Book Club Points An online book club awards points...Ch. 4 - Change for a Dollar Game Create a change -counting...Ch. 4 - Time Calculator Write a program that asks the user...Ch. 4 - Math Tutor Version 2 This is a modification of the...Ch. 4 - Software Sales A software company sells a package...Ch. 4 - Bank Charges A bank charges 15 per month plus the...Ch. 4 - Prob. 11PCCh. 4 - Color Mixer The colors red, blue, and yellow are...Ch. 4 - Running the Race Write a program that asks for the...Ch. 4 - Personal Best Write a program that asks for the...Ch. 4 - February Days The month of February normally has...Ch. 4 - Body Mass Index Write a program that calculates...Ch. 4 - Fat Gram Calculator Write a program that asks for...Ch. 4 - Prob. 18PCCh. 4 - The Speed of Sound in Gases When traveling through...Ch. 4 - Spectral Analysis If a scientist knows the...Ch. 4 - Freezing and Boiling Points The following table...Ch. 4 - Mobile Service Provider A mobile phone service has...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Python Tutorial #10; Math Functions in Python; Author: Art of Engineer;https://www.youtube.com/watch?v=OviXsGf4qmY;License: Standard YouTube License, CC-BY