Programming questions

I have a question below but I don't understand as I newbie

The header of the function ShowCost() is given below:
void ShowCost( float fltCost )
Identify the errors in the following statements, if any, in calling the function showCost().
A. showcost(fltTotal);
B. ShowCost( float fltTotal);
C. ShowCost();
D. fltPrice = ShowCost(fltTotal);

When is our assignment due?

Just use words to explain this line and you will have two of the four answers.

void ShowCost( float fltCost )

Alternatively, write a program containing those lines and compile it :smiley:

...but make sure you use more semicolons than the question setter, or you'll introduce even more errors.

not sure what's your background, but you should do some home work and some basic learning in programming.

As you requested for answer, the answer is 'A: showcost(fltTotal);', if you call this way you will get error because it's case sensitive.

Psst, they've all got errors.

AWOL:
Psst, they've all got errors.

none of the answer is correct :slight_smile:

I guess the compiler can tell what the problems are?

...R

yes it will, here it is

exit status 1
'showcost' was not declared in this scope

Since this is so obviously homework, I don’t think anyone should have given the answer.

Now that it’s done, however, an explanation wouldn’t go astray:-

void ShowCost( float fltCost ); // The function prototype.
A. showcost(fltTotal); // C++ is case sensitive, so this will fail.
B. ShowCost( float fltTotal); // When calling the function, you pass the (float) parameter, don’t declare it as ‘float’
C. ShowCost(); // A (float) parameter must be passed to the function.
D. fltPrice = ShowCost(fltTotal); // The function does not return a value, so "fltPrice = " is wrong.

A correct call to the function:-
ShowCost(fltTotal);

Assuming fitTotal is a float of course. Otherwise you'll get a pre processor automatic type conversion warning in good compilers if it can be converted and it will proceed with automatic casting of the value.

If fitTotal is an array of Boolean (for example) then it will fail with type mismatch

J-M-L:
Assuming fitTotal is a float of course. Otherwise you’ll get a pre processor automatic type conversion warning in good compilers if it can be converted and it will proceed with automatic casting of the value.

If fitTotal is an array of Boolean (for example) then it will fail with type mismatch

That’s why I said, at “B.”:- “When calling the function, you pass the (float) parameter”
and, at “C.”:- “A (float) parameter must be passed to the function.”

Yes of course that was just a complement to your statement

A correct call to the function:-
ShowCost(fltTotal);

Thank all for your comment as I will try it do too.