Adding a Max Bet Option for a Craps game

I am sure I'll save myself half a day by posting my question here. I need to
add an option where if I type "max" I can bet the maximum amount. Yes I have a lot of reviewing to do.

Also I spent a good amount of time formatting my pasted code below. Pasted from notepad++, anyone have any better suggestions that fit this posting format?

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
//CRAPS GAME
#include "stdafx.h"
#include <iostream> 
#include <cmath>
#include <cctype>
#include <string>
#include <cstdlib>

int main()
{
using namespace std;

	int start = 50; // starting amount
	int bet = 0;
	int sum = 0;
	//-----------------------------------------------------
	int max = start ; //I have also  used string and char, lost in general
        string play; //string for yes/no continuation of game
	//-----------------------------------------------------

//while (play != "no" && start > 0 ) // left in to show beginning
//{


cout << "Enter Bet (max " << start << "):" << endl;    
							
cin >> bet;

//I want to type "max" for my bet amount or numbers
// tried if statements, getline, lost in general

//-----------------------------------------
// number only check
//-----------------------------------------
    if (cin.fail())                                            			 
{
	cin.clear();
	cin.ignore();
	cout << "ERROR - Enter a number" << endl;
 	cout << endl;
	continue;
} 
		
//----------------------------------------------
//Check if you have that amount
//----------------------------------------------

if (bet > start || start <= 0)							
	{
	cout << "You don't have that much" << endl;
	continue;
	}

//} // while statement

} // main 

 
instead of cin bet, you need to read a string, and then check it to see if it =='max' (consider doing a to-lower on the string to make life better for yourself here), if it does, bet the max, if it does not, see if it is a legal numeric value, if so and that is < max, bet that, else fail and complain about invalid input or betting too much or not having enough or whatever. You could probably add one more check to bet all your money if what you have is < max.

strongly consider the least common header style. That is, only # include stuff you actually use. I didnt verify all those but I suspect you are not actually using much from cmath here, for example.
Last edited on
jonnin:

Thanks for the reply! For now I have used a char to check the bet. Sometime today or tomorrow I will start working on changing it to a string value and checking the entire cin input. So inputs such as 4###2 arent excepted.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (bets[0] == 'm' || bets[0] == 'M') // bets is the cin value, 'm' for max, 
{
	bet = start; // start is the starting user value ($50), while bet is used for the game input

}
else if (isdigit(bets[0]))
{
	bet = stoi(bets);  // convert cin value

}
else                             // not m or M , not a number
{
	cout << "ERROR - Enter a number or max" << endl;
	continue;

}
Topic archived. No new replies allowed.