roulette

i have home work to do a simple roulette. here is the code i got i know its stuff misplaced but i do it that way for some reasona nd i have extra things added , it is sloppy but only because i havent cleaned it because i keep erasing to figure it out, i dont want someone to give me the whole formula because i do want to lear but if some one can guide me on my issue, my issue is i dont know how to make it put the new amount after the win or loss and use that same amount the next time they bet. thats where my issue is, here is the code i got so far


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
#include<iostream>
using namespace std;
#include<Math.h>



void main()
{




	char op,e,z,o,q;
	int x,n,t,zero,bet,remaining,result,wins,losses,wheel;
	int start = 100;
	bet = 5;
	zero = 50;
	n = start + bet;
	t = start - bet;

	

	
	cout<<"welcome to roulette, you can bet on Even, Odd, or zero\n";
	cout<<"use E,O or Z, each bet is 5 dollars, if you bet Zero and win you win 50\n";
	cout<<"you can choose Q to quit game,the game ends automatically when the moneys gone\n\n\n\n";

	
	do
	{
		cout<<"you have "<<start<<endl;
		cout<<"please select E,O,Z,or,Q\n";
		cin>>op;


		if(op == 'e' || op == 'E')
		{
			for(int i=1;i<=1;i++)
			{

				x= rand() % 10;

				cout<<x<<endl;


			
			}
			




		}






		cout<<"do you want to continue\n";
		
					cin>>e;
	}
	while((e ==  'y')|| (e == 'Y'));

	

	


}



I thank you very much for any help. I have been doing this for only about 3 to 4 weeks now.
Well i suggest that you change the program to switch-case statements instead of the IFs, and the Do While, i think you can change it into only while..

if you want more help just say so.
.
.
.
.
char e = 'y';

while( e == 'Y' || e == 'y')
{
///////////program body////////////
/////////////////////////////////////////
/////////////////////////////////////////

cout<<"do you want to continue\n";
cin>>e;
}
.
.
.
I honestly think do/while is better the purpose of a do/while is to run a MINIMUM of 1 time and a while has a MINIMUM of 0. There are different ways you can keep track of the money acquired you can declare a value with it's initial amount outside of the loop or a static inside of the loop. Then when they earn money or loss money apply that to the current money.
ex:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
srand( time( NULL ) );
const short INITIALMONEY = 10 //setting a read only value to start with
short money = INITIALMONEY , input = 0; //start with 10 dollars
do 
{
    std::cout << "Guess my number ( 1- 10 )\n> " << std::endl;
    std::cin >> input;
    if( input == rand() % 10 + 1 )
    {
        ++money; //give him one dollar
    } else {
        --money; //take away a dollar
    }
} while( money > 0 ); //play while he has money left 
edward, I was going to use switch and thats what i started out with. this one i posted was one of many because i could not for the lif eof me figure out how to add the winning or subtract the losing and KEEP the new number instead of it going back to 100.


giblit, thank yout, it says the bet is 5 dollars though . there is no betting what you want its a safe bet of 5

thank everyone of you for your help
I wasn't doing the assignment for you I was showing you how you would keep track of his money =p btw use cmath not math.h.
math.h is the old non-standard library.
Last edited on
heres the code i got now, i ahve it where it makes the new number what its supposed to be but it only does it once


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
#include<iostream>
using namespace std;
#include<Math.h>



void main()
{




	char op,e;
	int x,n,t,zero,bet,result,wins,losses;
	int start = 100;
	bet = 5;
	zero = 50;
	n = start + bet;
	t = start - bet;

	

	
	cout<<"welcome to roulette, you can bet on Even, Odd, or zero\n";
	cout<<"use E,O or Z, each bet is 5 dollars, if you bet Zero and win you win 50\n";
	cout<<"you can choose Q to quit game,the game ends automatically when the moneys gone\n\n\n\n";

	
	do
	{
		cout<<"you have "<<start<<endl;
		cout<<"please select E,O,Z,or,Q\n";
		cin>>op;
		x= rand() % 10;

		switch(op)
		{
		case 'E':
			{
			
		
			for(int i=1;i<=1;i++)
			{

				

				cout<<x<<endl;
				if(x % 20 == 0)
				{
					cout<<"you win and your new balance is "<<n<<endl;
					start = n;
					
				}
				
				else
				{
					cout<<"you lose and your new balance is "<<t<<endl;
					start = t;
				}
				
				


			
			}
			}
			







		}




		

		






		cout<<"do you want to continue\n";
		cin>>e;
	}
	while((e ==  'y')|| (e == 'Y'));

	

	


}
Because n and t are outside of loop just do start += bet for them instead like on line 52 and -= line 58
Topic archived. No new replies allowed.