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
#include using namespace std; int main() int x=1,y=2; for (int i=0; i<3; i++) e{ x=x*y; 8{ } cout<
Q1)What are the final values of x and y? int x=1, y=6; if(x>1) if(y<5){ x=x+2; y=y+2; } else{ x=x-1; y=y-1; } x=x+1; y=y+1;        Ans: a.   x=1, y=4.   b. x=3, y=6. c. x=2, y=7. d. x=3, y=7. e. x=2, y=5.
Programming Exercise C++ Summary During the tax season, every Friday, the J&J accounting firm provides assistance to people who prepare their own tax returns. Their charges are as follows: If a person has low income (<= 25,000) and the consulting time is less than or equal to 30 minutes, there are no charges; otherwise, the service charges are 40% of the regular hourly rate for the time over 30 minutes. For others, if the consulting time is less than or equal to 20 minutes, there are no service charges; otherwise, service charges are 70% of the regular hourly rate for the time over 20 minutes. (For example, suppose that a person has low income and spent 1 hour and 15 minutes, and the hourly rate is $70.00. Then the billing amount is 70.00 X.40 X (45/60) = $21.00.) Instructions Write a program that prompts the user to enter yearly income, the hourly rate, the total consulting time. The program should output the billing amount. Your program must contain a function that takes as…

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