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
What did you find most interesting or surprising about the scientist Lavoiser?
1. Complete the routing table for R2 as per the table shown below when implementing RIP routing Protocol? (14 marks) 195.2.4.0 130.10.0.0 195.2.4.1 m1 130.10.0.2 mo R2 R3 130.10.0.1 195.2.5.1 195.2.5.0 195.2.5.2 195.2.6.1 195.2.6.0 m2 130.11.0.0 130.11.0.2 205.5.5.0 205.5.5.1 R4 130.11.0.1 205.5.6.1 205.5.6.0
Analyze the charts and introduce each charts by describing each. Identify the patterns in the given data. And determine how are the data points are related.   Refer to the raw data (table):

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