C++ program. Please help me with these questions, I know the answers to some of
ID: 3862248 • Letter: C
Question
C++ program. Please help me with these questions, I know the answers to some of them but I need a second thought for verification. Thank you in advance.
1)
You have received this warning when compiling a program:
What have you done and how should you fix it?
2)
The code below is part of a working program and has a logic error. Describe it, and indicate how to fix it.
(Remember that only partial code is shown here. The answer is not that this is an incomplete program and that a main function is needed.)
const int SENTINEL = -1;
int count = 0;
int sum = 0;
int num;
double average;
cout << "Enter a value: (or -1 to quit): " << endl;
cin >> num;
while (num != SENTINEL)
{
cout << "Enter a value: (or -1 to quit): " << endl;
cin >> num;
count++;
sum += num;
}
average = sum/count;
3)
You are writing a program to determine sales commission, where the following commission rates are used:
Write the constant declarations that will be needed in the code when calculating the commission. You can write these as define directives or as constant variables, but in either case, you must use standard and proper syntax.
(This is not asking to write a program or any code that will use these constants. Show only the constant declarations.)
4)
An assignment statement
5)
int processValue (int val)
{
if (val > 100)
return val - 100;
else if (val < 0)
return 0;
else
return val;
}
int num = 123;
int result = processValue (num);
After the call to processValue, what is the value of the variable num?
sales rate < 10,000 3% > 10,000 and <= 15,000 5% > 15,000 7%Explanation / Answer
2)The logic error in the given code is
both sum and count are declared as integers
because of that we may loss decimal values..'
so to fix it we may either declare one of them as double or, type cast one of them to double
3)
declaring constants for commision rates
#define low 0.03;
#define mid 0.05;
#define high 0.07;
4)A
5)value of variable num is 123
variable result is 23
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.