C++ How to Program (10th Edition)
C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
100%
Book Icon
Chapter 4, Problem 4.11E

(Correct the Code Errors) Identity and correct the errors (s) in each of the following:

  1. if (age >= 65); {
  2. cout << “Age is greater than or equal to 65” << end1;
    }
    else {
    cout << “Age is less than 65 << and end1” ;
    }
  3. if (age >= 65) {
  4. cout << “Age is greater than or equal to 65” << end1;
    else: {
    cout << “Age is less than 65<< end1”;
    }
  5. unsigned int x {1};
  6. unsigned int total;
    while (x <=10) {
    total += x;
    ++x;
    }
  7. While (x <=100)
  8. total +=x;
    ++x;
  9. while (y>0) {
  10. cout << y << end1;
    ++y;
    }

Expert Solution
Check Mark
To determine

a)

To find and correct errors in the given program segment.

Explanation of Solution

The given program segment contains errors in the following highlighted statements:

if(age>=65); {
cout<<"Age is greater than are equal to 65"<<endl;
}
else {
cout<<"Age is less than 65<<endl";
}       

Errors:

  • If the statement is ending with a semi-colon.
  • The keyword endl is enclosed within double-quotes. Double quotes should only contain string statements.

Correct code:

if(age>=65){
cout<<"Age is greater than are equal to 65"<<endl;
}
else {
cout<<"Age is less than 65"<<endl;
}       
Expert Solution
Check Mark
To determine

b)

To find and correct errors in the given program segment.

Explanation of Solution

The given program segment contains errors in the following highlighted statements:

if(age>=65){
cout<<"Age is greater than are equal to 65"<<endl;
}
else; {
cout<<"Age is less than 65 <<endl";
}       

Errors:

  • Else statement is ending with a semi-colon.
  • The keyword endl is enclosed within double-quotes. Double quotes should only contain string statements.

Correct code:

if(age>=65){
cout<<"Age is greater than are equal to 65"<<endl;
}
else {
cout<<"Age is less than 65"<<endl;
}       
Expert Solution
Check Mark
To determine

c)

To find and correct errors in the given program segment.

Explanation of Solution

The given program segment contains errors in the following highlighted statements:

unsigned int x{1};
unsigned int total;
while(x<=10){
	total + = x;
	++x;
}

Errors:

  • Incorrect use of assignment operator (=).

Correct code:

unsigned int x{1};
unsigned int total;
while(x<=10){
	total =+ x;
	++x;
}
Expert Solution
Check Mark
To determine

d)

To find and correct errors in the given program segment.

Explanation of Solution

The given program segment contains errors in the following highlighted statements:

if(age>=65); {
cout<<"Age is greater than are equal to 65"<<endl;
}
else {
cout<<"Age is less than 65<<endl";
}       

Errors:

  • If the statement is ending with a semi-colon.
  • The keyword endl is enclosed within double-quotes. Double quotes should only contain string statements.

Correct code:

if(age>=65){
cout<<"Age is greater than are equal to 65"<<endl;
}
else {
cout<<"Age is less than 65"<<endl;
}       
Expert Solution
Check Mark
To determine

e)

To find and correct errors in the given program segment.

Explanation of Solution

The given program segment contains errors in the following highlighted statements:

while(y>0){
	cout<<y<<endl;
	++y;
}

Errors:

  • The code segment contains a logical error. The while loop is an infinite loop since it will keep running since y is always incremented and will always remain positive.

Correct code:

while(y>0){
	cout<<y<<endl;
	--y;
}

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
I want to ask someone who has experiences in writing physics based simulation software. For context I am building a game engine, and want to implement physics simulation. There are a few approaches that I managed to find, but would like to know what are other approaches to doing physics simulation entry points from scenes, would you be able to visually draw me a few approaches (like 3 approaces)? When I say entry point to the actual physics simulation. An example of this is when the user presses the play button in the editor, it starts and initiates the physics system. Applying all of the global physics settings parameters that gets applied to that scene. Here is the use-case, I am looking for. If you have two scenes, and select scene 1. You press the play button. The physics simulation starts. When that physics simulation starts, you are also having to update the physics through some physics dedicated delta time because physics needs to happen faster update frequency. To elaborate,…
I want to ask someone who has experiences in writing physics based simulation software. For context I am building a game engine, and want to implement physics simulation. There are a few approaches that I managed to find, but would like to know what are other approaches to doing physics simulation entry points from scenes, would you be able to visually draw me a few approaches (like 3 approaces)?When I say entry point to the actual physics simulation. An example of this is when the user presses the play button in the editor, it starts and initiates the physics system. Applying all of the global physics settings parameters that gets applied to that scene.Here is the use-case, I am looking for. If you have two scenes, and select scene 1. You press the play button. The physics simulation starts. When that physics simulation starts, you are also having to update the physics through some physics dedicated delta time because physics needs to happen faster update frequency.To elaborate, what…
Male comedians were typically the main/dominant star of television sitcoms made during the FCC licensing freeze.   Question 19 options:   True   False In the episode of The Honeymooners that you watched this week, why did Alice decide to get a job outside of the home?   Question 1 options:   to earn enough money to buy a mink coat   to have something to do while the kids were at school   to pay the bills after her husband got laid off

Chapter 4 Solutions

C++ How to Program (10th Edition)

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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License