EBK C   PROGRAMMING:
EBK C PROGRAMMING:
8th Edition
ISBN: 9780357156025
Author: Malik
Publisher: Cengage Learning
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 2, Problem 22SA

Explanation of Solution

Errors in the program have been pointed out below each line of code.

#include<ioStream>
ioStream should be iostream as C++ is case sensitive.

using std;
The statement is supposed to specify the namespace. Correct statement:
using namespace std;

const double  DECIMAL# = 5.50;
The name of the identifier (variable) should not contain # as only letters, digits, and underscores are allowed. Correct statement:
const double  DECIMAL = 5.50;

const string blanks = "   "
The statement should terminate with a semi-colon. Correct statement:
const string blanks = "   ";

int ()main
The brackets should come after the word main as main is a function in C++ and any function identifier is followed by brackets (empty or otherwise). Correct statement:
int main()

{
int height, weight;
(no error)

double 10%discount
The name of the identifier (variable) should not contain # as only letters, digits, and underscores are allowed. It should begin with an underscore or letters and not digits. Also the statement should be terminated with a semi-colon. Correct statement:
double discount;

double billingAmount$;
double bonus;
int hoursWorked = 45;
(no error)

height = 6.2;
The above statement does not have a syntax error. However, since the variable is of int type implicit conversion to int type will take place and the value of 6.2 would be truncated to 6, the intended functionality would not be accomplished. However, since there is no syntax error, we will keep the statement as it is.

weight = 156;
(no error)

cout << height << " " << weight << end;
The above statement ends with a wrong manipulator. It should be endl and not end. Correct statement:
cout << height << " " << weight << endl;

discount = (2 * height + weight) % 10.0
The statement has multiple errors. The % operator expects only integer operands and hence, it should be 10 and not 10.0. The semi-colon terminator is missing. Correct statement:
discount = (2 * height + weight) % 10;

price = 49.99;
The variable has not been declared properly as the data type is missing. Since the variable intends to hold a floating point value, it would be appropriate to declare it as a double type...

Blurred answer
Students have asked these similar questions
#include #include #include #include #include using namespace std; int main (){ const double PI = 3.14159265359; return 0; }
Q 6:- Specify the local and Global variables used in the code below and express the reason r'. #include int a=10,b; void main() { printf("a = 8d and b=%d“,a,b) ; #include void main() { int x-23, y-4; printf("x = %d and y=sd“,x,y);
#include using namespace std; int main() int x=1,y=2; for (int i=0; i<3; i++) e{ x=x*y; 8{ } cout<

Chapter 2 Solutions

EBK C PROGRAMMING:

Ch. 2 - Which of the following are valid C++ assignment...Ch. 2 - Write C++ statements that accomplish the...Ch. 2 - Write each of the following as a C++ expression....Ch. 2 - Prob. 14SACh. 2 - Suppose x, y, and z are int variables and wandt...Ch. 2 - 16. Suppose x, y, and z are int variables and x =...Ch. 2 - Suppose a and b are int variables, c is a double...Ch. 2 - 18. Write C++ statements that accomplish the...Ch. 2 - Which of the following are correct C++ statements?...Ch. 2 - Give meaningful identifiers for the following...Ch. 2 - 21. Write C++ statements to do the following....Ch. 2 - Prob. 22SACh. 2 - The following program has syntax errors. Correct...Ch. 2 - Prob. 24SACh. 2 - Prob. 25SACh. 2 - Preprocessor directives begin with which of the...Ch. 2 - 27. Write equivalent compound statements if...Ch. 2 - 28. Write the following compound statements as...Ch. 2 - 29. Suppose a, b, and c are int variables and a =...Ch. 2 - Suppose a, b, and sum are int variables and c is a...Ch. 2 - Prob. 31SACh. 2 - Prob. 32SACh. 2 - Prob. 33SACh. 2 - Prob. 34SACh. 2 - 1. Write a program that produces the following...Ch. 2 - Prob. 2PECh. 2 - Prob. 3PECh. 2 - 4. Repeat Programming Exercise 3 by declaring...Ch. 2 - Prob. 5PECh. 2 - Prob. 6PECh. 2 - 7. Write a program that prompts the user to input...Ch. 2 - Prob. 8PECh. 2 - 9. Write a program that prompts the user to enter...Ch. 2 - 10. Write a program that prompts the user to input...Ch. 2 - 11. Write a program that prompts the capacity, in...Ch. 2 - 12. Write a C++ program that prompts the user to...Ch. 2 - 13. To make a profit, a local store marks up the...Ch. 2 - 14. (Hard drive storage capacity) If you buy a 40...Ch. 2 - 15. Write a program to implement and test the...Ch. 2 - 16. A milk carton can hold 3.78 liters of milk....Ch. 2 - 17. Redo Programming Exercise 16 so that the user...Ch. 2 - Prob. 18PECh. 2 - 19. Write a program that prompts the user to input...Ch. 2 - 20. For each used car a salesperson sells, the...Ch. 2 - 21. Newton's law states that the force, , between...Ch. 2 - 22. One metric ton is approximately 2,205 pounds....Ch. 2 - 23. Cindy uses the services of a brokerage firm to...Ch. 2 - 24. A piece of wire is to be bent in the form of a...Ch. 2 - 25. Repeat Programming Exercise 24, but the wire...Ch. 2 - 26. A room has one door, two windows, and a...Ch. 2 - Prob. 27PECh. 2 - 28. In an elementary school, a mixture of equal...Ch. 2 - 29. A contractor orders, say, 30 cubic yards of...
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