Homework: calculate test scores

Hello all,
I'm in my first C++ class and in this chapter we are learning about functions. my assignment is to create a program that uses 3 functions and calls these functions in main. the functions are getScore, calcAverage and findLowest; they should be self explanatory.

void getScore should ask the user for a test score, store it in a reference parameter variable and validate it. this function should be called by main once for each of the five test score to be entered

void calcAverage should calculate and display the aver of the four highest scores. This function should be called just once by main, and should be passed the five scores.

int findLowest should find and return the lowest of the five scores passed to it. It should be called by calcAverage, which uses the function to determine which of the five scores to drop

PEBKAC! Whoever wrote this function this way just doesn't know what they're doing. The array syntax can communicate what's expected if the programmer uses it consistently, so I really don't see the use of types only as the problem.

Code:

void Display (String* name);
void Display (String name[]);

Part of the mystery here is what String could be. Parameter names aren't the silver bullet. Documentation is.

Some tools ... parses the prototypes to give additional information about the function the programmer is trying to call. Hence, when the names of the parameters are missing from the prototypes, IntelliSense cannot display what parameters the function takes, not being very helpful to the programmer.

This is the same argument as before so it should probably be gone. Intellisense does not stop working, it just has less to say.

Typically, when a function header changes, so must the prototype. A typical resolution to this problem is to copy the function head and paste it and use it as a prototype, as well. If then the programmer proceeds to strip the names of the parameters, that incurs extra work.

That doesn't count. Typing arguments never count, since typing is a massive part of our discipline. You can do the same things in a different order and the only work is required work.

The article doesn't mention probably the best thing about parameter names. They make documentation -- in the source file in comments or elsewhere -- easy to follow. No one wants to write "argument 1" or "argument 2" to explain their function.

I've made some minor changes. I don't know if they're to your taste or not.
Regarding the functions, yes, I know they're horrible, so if want to change them, give a better example.
And you know you can change the wiki yourself, yes? If you disagree with how it's written, feel free to update it yourself.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

I have another homework assignment i need help with. I'm asked to build a program that uses a function called isPrime. The function should do a primality check against a user given number. I'm in the process of writing out psuedo-code for this assignment and can't wrap my head around how to do the check. I know prime numbers can only be divisible by themselves and 1 only... but how do i write that into a function? it sounds inefficient to do a for loop but its really the only thing i can think of. any help would be greatly appreciated.

I have another homework assignment that lets the user play rock paper scissors with the computer. Please see my code; I had it running until i added in my winner function. I am getting an error saying i am running an unsafe bool combination. The compiler threw and error when i tried to make these string types and suggested i change the to bool... so i did and it still doesn't like it. Can someone advise what i did wrong?

Well, a bool can only be true of false (ie, it's a boolean). Yet, you treat it as if it were a string.
I'd look up enums here if I were you (pay special heed to enum class if your compiler supports it).
Oh, and you are using = instead of == for comparison.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

Well, a bool can only be true of false (ie, it's a boolean). Yet, you treat it as if it were a string.
I'd look up enums here if I were you (pay special heed to enum class if your compiler supports it).
Oh, and you are using = instead of == for comparison.

Elysia,

you were correct, changing = to == fixed the error. while running I encountered a new error it says, no suitable constructor exists to convert void() to basic string()

So first of all, playerChoice and compChoice aren't defined in main. No such variables exist in main. So why do you think you can pass some non-existing variables to a function?
Secondly, playerChoice and compChoice are names of functions. It's just bad practice to name local variables with the same name.
As a consequence of your naming rules, you are passing function pointers to winner, which aren't strings, and so the compiler complains.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.