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

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");

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; }

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; }

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?
Chapter 3 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (4th Edition)
Problem Solving with C++ (10th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Introduction To Programming Using Visual Basic (11th Edition)
- using r language Obtain a bootstrap t confidence interval estimate for the correlation statistic in Example 8.2 (law data in bootstrap).arrow_forwardusing r language Compute a jackknife estimate of the bias and the standard error of the correlation statistic in Example 8.2.arrow_forwardusing r languagearrow_forward
- using r languagearrow_forwardThe assignment here is to write an app using a database named CIT321 with a collection named students; we will provide a CSV file of the data. You need to use Vue.js to display 2 pages. You should know that this assignment is similar, all too similar in fact, to the cars4sale2 example in the lecture notes for Vue.js 2. You should study that program first. If you figure out cars4sale2, then program 6 will be extremely straightforward. It is not my intent do drop a ton of new material here in the last few days of class. The database contains 51 documents. The first rows of the CSV file look like this: sid last_name 1 Astaire first_name Humphrey CIT major hrs_attempted gpa_points 10 34 2 Bacall Katharine EET 40 128 3 Bergman Bette EET 42 97 4 Bogart Cary CIT 11 33 5 Brando James WEB 59 183 6 Cagney Marlon CIT 13 40 GPA is calculated as gpa_points divided by hrs_attempted. GPA points would have been arrived at by adding 4 points for each credit hour of A, 3 points for each credit hour of…arrow_forwardI need help to solve the following case, thank youarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningCOMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE LSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning




