guessing game

im trying to write a recursive function that will never ask user for a number but the program will guess by asking if the number is greater then a number (the user says y/n) then the computer asks again .... i dont really understand recursive function at all and am having a terrible time with this any help pointing me in the right direction would be greatly appreciated
You should study recursion in depth first. As you know, if you don't understand that you won't be able to write the program. I assume this is an assignment of some sort; you should probably consult your textbook on the topic.
i have a bunch of my program written now but i am stuck and dont know where to go with it
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <math.h>
#include <stdlib.h>

using namespace std;



bool isYourNumber(int number)
{
	char response;
	
	do 
	{
		// Ask the user if their number is the given number
		cout << "Is the number " << number << "? (y/n) ";
		// Get their response
		cin >> response;
	} 
	while (response != 'y' && response != 'Y' &&
	       response != 'n' && response != 'N');
	
	return ((response == 'y') || (response == 'Y'));
}




bool isYourNumberGreaterThan(int number)
{
	char response;
	
	do 
	{
		// Ask the user if their number is the given number
		cout << "Is the number greater than " << number << "? (y/n) ";
		// Get their response
		cin >> response;
	} 
	while (response != 'y' && response != 'Y' &&
	       response != 'n' && response != 'N');
	
	return ((response == 'y') || (response == 'Y'));
}






int askFor(srand %101)
{
  char yes= ('y' || 'Y');
  char no= ('n' || 'N');
  int number = (start+end)/2;

  cout << " is the number " << number << "?" << endl;
       if (yes=='y' || yes== 'Y')
        {
          cout << "i'm awesome, i knew i could get it right!" << endl;
               return number;
        }     
       else
           {
                cout << "is the number greater than " << number << "?" << endl; 
            if (yes== 'y' || yes== 'Y')
            {
            return askFor(number, end);
            }
            else 
            return askFor(start,number);
           }
}


int main()
{
  askFor;
  
  
  return 0;
}
Um I don't think this even compiles.
int askfor(srand%101) {
Read up on functions. You try to call this function recursively with two parameters, but the function's parameter list is screwed up.

1
2
char yes= ('y' || 'Y');
char no= ('n' || 'N');

This compiles but doesn't do anything useful. I'm not even sure what you are trying to do here.

askFor;
You're trying to call a function here that (as above) is probably intended to take two parameters...but here you don't even use parentheses to call it.

The compiler is not going to look at function names and guess parameters or code at all, though it looks like you are expecting it to...
Topic archived. No new replies allowed.