Concept explainers
(Correct the Code Errors) Identity and correct the errors (s) in each of the following:
- if (age >= 65); { cout << “Age is greater than or equal to 65” << end1;
- if (age >= 65) { cout << “Age is greater than or equal to 65” << end1;
- unsigned int x {1}; unsigned int total;
- While (x <=100) total +=x;
- while (y>0) { cout << y << end1;
}
else {
cout << “Age is less than 65 << and end1” ;
}
else: {
cout << “Age is less than 65<< end1”;
}
while (x <=10) {
total += x;
++x;
}
++x;
++y;
}
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; }
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; }
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; }
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; }
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?
Chapter 4 Solutions
C++ How to Program (10th Edition)
- #include using namespace std; int main() int x=1,y=2; for (int i=0; i<3; i++) e{ x=x*y; 8{ } cout<arrow_forwarddebugarrow_forwardVoid Do1 (int: &, a. int &b) { a = 5; a = a + b; b = a + 2; } Int main() { Int x = 10; Do1 (x,x); Cout << x << endl; } The output of this program isarrow_forwardint x1 = 66; int y1 = 39; int d; _asm { } mov EAX, X1; mov EBX, y1; push EAX; push EBX; pop ECX mov d, ECX; What is d in decimal format?arrow_forwardFind errors / syntax error. Write line numberarrow_forwardPlease explain this question void main() {int a =300; char *ptr = (char*) &a ; ptr ++; *ptr =2; printf("%d", a); }arrow_forward(CLO3) Read the following description and answer the following questions about it: Problem Description: A car dealership allows customer to purchase their new cars with different options. At this time, those options are color, model, and air condition, as shown below in class CustomerOrder. Of course, the dealership wants the software to be flexible enough to be able to add more options in the future, if needed. CustomerOrder -carColor: String -carModel: String -hasAirCondition: boolean Q1) Write the full required code in Java to use the Builder design pattern to create class CustomerOrder. Q2) Write a Java main() method to create an object of class CustomerOrder with color "red" and without air condition.arrow_forwardQ3: (Tax Calculator) Develop a Java program that determines the total tax for each of four citizens. The tax rate is 10% for earnings up to 50,000 RM earned by each citizen and 15% for all earnings in excess of that ceiling. You are given a list with the citizens’ names and their earnings in a given year. Your program should input this information for each citizen, then determine and display the citizen’s total tax. Use class Scanner to input the data.arrow_forwardc++arrow_forwardvoid funOne(int a, int& b, char v); void main() { int num1=10; char ch='A'; funOne(num1, 15,ch)<arrow_forwardC++ Project ( Build the requested system 100% into a C++ environment, excluding Class framework & All defined variables must be represented as pointer type, int, char etc)Scenario:A bookshop (PRIMER BOOKSHOP) wants to maintain the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher, and stock position. Whenever a customer wants a book, the sales personnel inputs the title and author, and the system searches the list and displays whether it is available or not.- If it is not, an appropriate message is displayed.- If it is, then the system displays the book details and requests for the number of copies required.- If it is requested, copies of the book details and requests for the number of copies required are available, the total cost of the requested copies is displayed and your system needs to update the database.- Sales personnel, from time to time are allowed to update the latest stock and price to the created…arrow_forward#include #include void main(void) {int number; Cout > number; if ( number > 100) cout <<" number is greater then 100" ; else cout <" number is not greater than 100" ;arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education