Functions

So I am supposed to be programming a basic number guessing game, however, I am having some difficulties. When you run my program it will not tell you whether your guess is too high, too low, or correct. I am not sure whether it is within the processGuess function or the play part but that is why I am here. I am also supposed to cout how many attempts it took but in the directions it doesn't hint to using a counter so how would I go about doing that?

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>

using namespace std;

#include "Random.h"

int getSecret();
int getGuess();
int processGuess(int guess, int secret);
int play(int secret);

int main()
{
	void randomInit();

	char Ready_Play;
	int count = 1;
	
	cout << "Are you ready to play? (y/n) ";
	cin >> Ready_Play;
	
	while (Ready_Play == 'n')
		return 0;
	
	while (Ready_Play == 'y')
	{
	
		int secret = getSecret();
		
		int guess = getGuess();
	
		int processGuess(int guess, int secret);
	
		int play(int secret);
	}

	cout << "Are you ready to play again? (y/n)";
	cin >> Ready_Play;
	
	return 0;
}

int getSecret()
{
	int secret = getRandomInt(1, 100);
	return secret;
}

int getGuess()
{
	int guess;
	cout << "Enter your guess: ";
	cin >> guess;
	
	while (guess < 1 || guess > 100)
		{
		cout << "Invalid guess, please try again" << endl;
		cin >> guess;
		}
	return guess;
}

int processGuess(int guess, int& secret)
{
	if (secret > guess)
			{
			//count++;
			secret = 1;
			}
			
		else if (secret < guess)
			{
			//count++;
			secret = -1;
			}
			
		else
			{
			secret = 0;
			}
			
		return secret;	
		
}

int play(int secret)
{
	while (secret != 0)
		{
		if (secret == 1)
			{
				cout << "Too high." << endl;
			}
		
		else if (secret == -1)
			{
				cout << "Too low." << endl;
			}
		}
		
	if (secret == 0)
		{
		cout << "You got it!" << endl;
		}
		
	//cout << "It took you " << count << "number of guesses." << endl;
}
Topic archived. No new replies allowed.