### 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

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071`` ``````#include using namespace std; #include 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 "<>op; if(op == 'e' || op == 'E') { for(int i=1;i<=1;i++) { x= rand() % 10; cout<>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:
 ``1234567891011121314`` ``````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

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899`` ``````#include using namespace std; #include 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 "<>op; x= rand() % 10; switch(op) { case 'E': { for(int i=1;i<=1;i++) { cout<>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.