Help with guessing game code.

So I have to write a guessing game code and I'm having some real trouble with it any help would be awesome. Whenever I compile and run the code I get the error "too few arguments to function `void GiveHint(int, int)'" Anyway the idea of this code is to use a function and then call it in int main. I'm not trying to generate a random number I'm just coding that number in. Here is my code thanks.

P.S. This is probably a stupid or novice mistake but thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  #include <iostream>
using namespace std;

void GiveHint(int, int);
//pre:
//post:
void GiveHint(int Secret, int Guess)
{
	Secret = 47;
	if (47 == Guess)
    {
    
       cout<<"You guessed correctly congratulations"<<endl;
       
    }
    else if (47 < Guess)
    {
    
       cout<<"You guessed too high please guess again"<<endl;
       
    }
    
    else (47 > Guess);
    {
    
       cout<<"You guessed too low please guess again"<<endl;
       
    }
}

int main()                               //Starting point of execution
{
    GiveHint();                 //Function call to VolumeOfRectangle(), int main() is on hold
     
    return 0;                            //End of execution
}
Last edited on
In your main() function you call a GiveHint() method with NO parameters.

However on line 7 you have told the compiler about a GiveHint() function that takes TWO parameters.

In your function you shouldn't set the input values like you're doing now. You pass these in when you call the method on line 33.

e.g.


1
2
3
4
5
6
7
8
9
10
11
12
main()
{
    int theSecret = 47;    
    int theGuess = -1;      //initialise it to something.

    // Ask the user for his/her guess, set the value of theGuess to this.

    // Call function like this:
    GiveHint(theSecret, theGuess)

}
Thanks for the reply but the part where you set the guess as -1 I'm having the user input the guess so how would I do that something isn't clicking for me today. I issued the cin statement for the user to input the guess. Frankly all of this function stuff and parameters has been confusing me.
Last edited on
http://www.cplusplus.com/doc/tutorial/basic_io/

Especially the section about stringstream, because you want the user input to be converted to an integer.
To have a user enter a value and store it in "theGuess", a simple cin>>theGuess; should do the trick. That value can then be passed into "GiveHint" as mutexe showed.
Topic archived. No new replies allowed.