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
DO NOT COPY FROM OTHER WEBSITES Correct and detailed answer will be Upvoted else downvoted. Thank you!
#include using namespace std; int main() int x=1,y=2; for (int i=0; i<3; i++) e{ x=x*y; 8{ } cout<
debug

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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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