### Is this a good program?

Idk how to explain it, but it seems so messy. I am brand new to programming.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 #include #include // for time() #include using namespace std; int main () { int dieOne=0; int dieTwo=0; int roll=0; int point=0; double odds=0; double betmoney=50; srand(time(0)); //makes time random seed for(int game=1; game<4; game++) { dieOne=(rand()%6)+1;//creates dice dieTwo=(rand()%6)+1; roll=dieOne+dieTwo; cout<

Is there anything I can do to make it better?
betmoney+50;
This will not do anything.

If you want to increase betmoney by 50 you have to write
betmoney = betmoney + 50;
or
betmoney += 50;
You could use a array.
like instead of:
int dieOne=0;
int dieTwo=0;

You could just do
die[2]

You mention that you're new to programming. Have you just covered basic o/p (i.e. cout) and loops, etc so far??

To improve you code you could (in addition to fixing your maths like Peter87 says):

1. tidy it up a bit (you did say it's messy)

2. simplfy the last if else in both you if statements (if I understand correctly, the last test is for all remaining possible numbers?)

3. you could use a little helper function to make what's going on a bit more obvious?

 1234 int rollDie() { return (rand()%6)+1; }

 12345678 ... for(int game=1; game<4; game++) { dieOne=(rand()%6)+1;//creates dice dieTwo=(rand()%6)+1; ....

4 Tighten up the scope of some of you variables. e.g. roll is only used inside the for loop.

5. And finally, are you allowed to carry on playing when you've run out of money?

Andy

PS I think Maxim's suggestion about the array is a bit borderline here. Might come in useeful later, though?
Last edited on
Topic archived. No new replies allowed.