Computer Science Canada Weird Hanging |
Author: | Clayton [ Sat Sep 09, 2006 6:08 pm ] | ||
Post subject: | Weird Hanging | ||
hey, this is my *first* program written in c++, i am using MinGW for my compiler, this program compiles fine, and runs, however, after you enter your bet, it just hangs, and i dont know why, here is my code:
im sure some of you are having heart attacks right now and thats fine, plz let me know how i can fix this up and make it better ![]() |
Author: | wtd [ Sat Sep 09, 2006 6:20 pm ] |
Post subject: | |
You have a one character error. The outermost while loop in your main function. What happens in the body of that loop? |
Author: | Clayton [ Sat Sep 09, 2006 6:53 pm ] | ||
Post subject: | |||
ok here is my current code so far:
compile and run it, and you will see that if you roll a point number, you seem to roll it on the very next roll every time (maybe i havent tested this thouroughly enough, but i think i have) |
Author: | bugzpodder [ Sun Sep 10, 2006 1:37 pm ] |
Post subject: | |
here is a hint on how to debug. I wont do it for you. you should confirm your theory by deleting everything (well comment it out) and just call your die_roll function multiple times. if it returns the same number everytime, you know die_roll function needs to be changed, otherwise something else is wrong. |
Author: | md [ Sun Sep 10, 2006 3:40 pm ] |
Post subject: | |
You should also try to initialize variables before comparing them to something. |
Author: | wtd [ Sun Sep 10, 2006 3:56 pm ] |
Post subject: | |
And if your while loop is going to run at least once... That's the classic place to use the do-while loop. |
Author: | bugzpodder [ Sun Sep 10, 2006 3:58 pm ] |
Post subject: | |
not sure if its what wtd meant in his first post, but i dont think while(bet < money); loop gets executed at all. |
Author: | md [ Sun Sep 10, 2006 7:29 pm ] |
Post subject: | |
bugzpodder wrote: not sure if its what wtd meant in his first post, but i dont think
while(bet < money); loop gets executed at all. It does because money is set to 500 and bet is set to money + 1. [syntax]int money, die1, die2, point, bet = 0; money = 500; bet = money + 1; [/syntax] Bet is set twice, which isn't very efficient; but it does run. However because die1 and die2 are not initialized before they are compared in the commented out (and pointless) loops; which could have caused problems. |
Author: | bugzpodder [ Mon Sep 11, 2006 12:08 pm ] |
Post subject: | |
so bet<money is evaulated to false and the loop does not run? |
Author: | Clayton [ Mon Sep 11, 2006 8:00 pm ] | ||
Post subject: | |||
ok, i got the game to *run*, however, when you roll a point, you will always roll it again to win the round, i dont know why it does it, but i have no idea how to fix it, or whats causing it, my code so far:
|
Author: | OneOffDriveByPoster [ Thu Sep 14, 2006 7:28 am ] |
Post subject: | |
Don't have time to test my theory, but someone already told you: your die_roll() does something it shouldn't. |