Guessing game question

I'm writing a program where the user has 6 chances to guess a random number, but I cannot think of another way to write the code so that if the user gets the number right on the 6th try, it will say the user won. Currently even if the user gets the number right on the 6th try it still says the user lost. I cannot think of another way to write the code, any suggestions?

ETA: This is all that can be in the function. CalcMoney only calculates the amount he user has. A different function determines if the user won or not, which is part of why i'm having trouble.

This is the function it's in:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int CalcMoney (int amountWon, int betAmount, int guessNum)
	
{
	if (guessNum == 6)
	{
		cout << "You lost $" << betAmount << endl;
		amountWon = (-betAmount);
	}
	else if (guessNum < 6)
	{
		amountWon = betAmount / guessNum;
		cout << "You just won $" << amountWon << endl;
	}
	return amountWon;
}
Last edited on
.
Last edited on
How about changing guessNum == 6 to guessNum > 6 and guessNum < 6 to guessNum <= 6 ?
its a bit like the gumball game that alot of begginers try to use:


#include <iostream>
#include <ctime>

using namespace std;

int main(void) {
	int iGumballs;
	int iUserguess;
	int iguesses = 0;

	while (true) {
		system("CLS");
		cin.clear();
		iguesses = 0;

		srand(static_cast<unsigned int>(time(0)));
		iGumballs = rand() % 1000 + 1;
		cout << "How many Gumballs are in the Gumball jar? 1-1000" << endl;
		do
		{
			cout << "Enter your guess: ";
			cin >> iUserguess;
			if (iUserguess > iGumballs) {
				cout << "Too high, try again!" << endl << endl;
			}
			if (iUserguess < iGumballs) {
				cout << "Too low, try again!" << endl << endl;
			}
			iguesses++;
		} while (iUserguess > iGumballs || iUserguess < iGumballs);
		cout << "You guessed the right amount of Gumballs!" << endl << "Congratulations!!" << endl << endl;
		cout << "You took " << iguesses << " guesses, to get the correct amount of Gumballs!" << endl << endl;
		system("PAUSE");
	}
	return 0;
}

Topic archived. No new replies allowed.