MYPROGRAMMINGLAB WITH PEARSON ETEXT
MYPROGRAMMINGLAB WITH PEARSON ETEXT
8th Edition
ISBN: 9780134225340
Author: Deitel
Publisher: PEARSON
bartleby

Videos

Textbook Question
100%
Book Icon
Chapter 3, Problem 3.10E

Indentify and correct the errors in each of the following. [Note: There may be more than one error in each piece of code.]

Chapter 3, Problem 3.10E, Indentify and correct the errors in each of the following. [Note: There may be more than one error

Expert Solution
Check Mark
Program Plan Intro

a. To identify and correct the error in the given codes.

Explanation of Solution

The error is in the first line of the code. The “if” statement shouldn’t end with a semicolon.

The correction involves the removal of the statement terminator (;) at the end of the first line of code because if there will be semicolon the puts statements won’t get executed.

The correct code will be −

if(age>=65)
puts("Age is greater than or equal to 65\n");
else
puts("Age is less than 65\n");
Expert Solution
Check Mark
Program Plan Intro

b. To identify and correct the error in the given codes.

Explanation of Solution

There is as such no error with the syntax or logical of the given code segment.However, it is always recommended to initialize the variables with some initial values in order to avoid problem of garbage value. Therefore, the variable “total” should be initialized with 0.

The correct code

int x=1, total =0;
while(x<=10)
{
    total+=x;
++x;
}
Expert Solution
Check Mark
Program Plan Intro

c. To identify and correct the error in the given codes.

Explanation of Solution

There are two errors in the given code.

The first correction involves the correction of name of the keyword while from “While” to “while”.

The second correction involves the enclosing the second and third statement withincurly braces.

So, the correct code will be as follows-

while(x<=100)
{
    total+=x;
++x;
}
Expert Solution
Check Mark
Program Plan Intro

d. To identify and correct the error in the given codes.

Explanation of Solution

The given code has the error in the while statement. The given statement is an infinite loop because y will keep on increasing (provided base value of y is positive) and will always be greater than 0.

The above problem can be solved by decrementing the y-value instead of incrementing.

The correct code will be as follows-

while(y>0)
{
printf("%d\n",y);
--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!
08:43
Students have asked these similar questions
Urgent help needed!#!
[Updated[ Python Code Pt1: Algorithms and Data Structures Please use the sample input to see if the code works, as the output of the final code, must be the same as the correct output. Follow the details and notes provided and show the complete working sample code. Additionally, include comments to make the code easier to understand. I will show how the output was found (check K);Note: The final code should result in correct output (check I) if sample input A (check H) is used, or else I will give an automatic thumbs down A. TASKThe user inputs a path system and the work needed to traverse them. The goal is to Identify the relationships between paths, whether they have sequential, adjacent, or null relationships. For every sequential and adjacent relationship, give their work done based on the formula (check D). B. SAMPLE A path system illustration //See Image C. Relationship Examples with Sample A as basisSequential relationships: Path1 and Path2 as they are single paths that are…
(Python matplotlib or seaborn) CPU Usage We have the hourly average CPU usage for a worker's computer over the course of a week. Each row of data represents a day of the week starting with Monday. Each column of data is an hour in the day starting with 0 being midnight. Create a chart that shows the CPU usage over the week. You should be able to answer the following questions using the chart: When does the worker typically take lunch? Did the worker do work on the weekend? On which weekday did the worker start working on their computer at the latest hour?   cpu_usage = [ [2, 2, 4, 2, 4, 1, 1, 4, 4, 12, 22, 23, 45, 9, 33, 56, 23, 40, 21, 6, 6, 2, 2, 3], # Monday [1, 2, 3, 2, 3, 2, 3, 2, 7, 22, 45, 44, 33, 9, 23, 19, 33, 56, 12, 2, 3, 1, 2, 2], # Tuesday [2, 3, 1, 2, 4, 4, 2, 2, 1, 2, 5, 31, 54, 7, 6, 34, 68, 34, 49, 6, 6, 2, 2, 3], # Wednesday [1, 2, 3, 2, 4, 1, 2, 4, 1, 17, 24, 18, 41, 3, 44, 42, 12, 36, 41, 2, 2, 4, 2, 4], # Thursday [4, 1, 2, 2, 3, 2, 5, 1, 2, 12, 33, 27, 43, 8,…

Chapter 3 Solutions

MYPROGRAMMINGLAB WITH PEARSON ETEXT

Ch. 3 - (Salary Calculator) Develop a program that will...Ch. 3 - (Predecrementing vs. Postdecrementing)Write a...Ch. 3 - (Printing Numbers from a Loop) Write a program...Ch. 3 - (Find the Largest Number) The process of finding...Ch. 3 - (Tabular Output) Write a program that uses looping...Ch. 3 - (Tabular Output) Write a program that utilizes...Ch. 3 - (Find the Two Largest Numbers) Using an approach...Ch. 3 - (Validating User Input) Modify the program in...Ch. 3 - Prob. 3.28ECh. 3 - Prob. 3.29ECh. 3 - (Dangling-Else Problem) Determine the output for...Ch. 3 - (Another Dangling-Else Problem) Modify the...Ch. 3 - Prob. 3.32ECh. 3 - (Hollow Square of Asterisks) Modify the program...Ch. 3 - (Palindrome Tester) A palindrome is a number or a...Ch. 3 - (Printing the Decimal Equivalent of a Binary...Ch. 3 - (How Fast Is Your Computer?) How can you determine...Ch. 3 - (Detecting Multiples of 10) Write a program that...Ch. 3 - (Counting 7s) Write a program that reads an...Ch. 3 - (Checkerboard Pattern of Asterisks) Write a...Ch. 3 - (Multiples of 2 with an Infinite Loop) Write a...Ch. 3 - (Diameter, Circumference and Area of a Cirle)...Ch. 3 - Whats wrong with the following statement? Rewrite...Ch. 3 - (Sides of a Triangle) Write a program that reads...Ch. 3 - (Sides of a Right Triangle) Write a program that...Ch. 3 - (Factorial) The factorial of a nonnegative integer...Ch. 3 - (World-Population-Growth Calculator) Use the web...Ch. 3 - (Target-Heart-Rate Calculator) While exercising,...Ch. 3 - (Enforcing Privacy with Cryptography) The...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
A byte is made up of eight a. CPUs b. addresses c. variables d. bits

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

What is the purpose of an objects sizing handles?

Starting Out With Visual Basic (8th 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
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I;License: Standard YouTube License, CC-BY
Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U;License: Standard Youtube License