My first suggestion would be to write functions that match the assignment suggestions.
1. int random();
int random();
OK so far
2. string input();
int input();
You return an int, but the suggestion was string.
3. string compChoice(int);
string compChoice(string);
The suggestion was to pass an int, not a string.
At a guess, you're meant to pass the result of random() into the function, not call random() within the function.
> string inputChange(string);
Huh?
If input() did what was supposed to, this wouldn't be necessary.
4. void displayCompChoice(string);
void displayCompChoice(string);
Looks good, but it calls compChoice(). Again, this is a parameter that gets passed in.
5. bool compare(string, string);
bool compare(string, string);
Seems OK, if a little strangely named.
>string h, d, c, k, w;
Pick meaningful names.
Your main should be something like this
1 2 3 4 5 6 7 8 9 10
|
string human = input();
string computer = compChoice(random());
// call the two display functions
if ( compare(human,computer) ) {
cout<<"You Win!"<<endl;
cout<<human << " wins over "<< computer << endl;
} else {
cout<<"Computer Wins!"<<endl;
cout<<computer<<" wins over " << human << endl;
}
|