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
State whether the following are true or false. If the answer is false, explain why.b) The break statement is required in the default case of a switch selection statement.
Explain these c++ statements void bar(int panam) {panam +=1;}
Fill in the blanks (using C programming) that gives the binary system numbers of the input. The output order should be as given and you are not able to change the code inside void decimalToBinary() and int main().

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
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
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
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