So i am trying to create a sort of dice game that when the numbers 7 or 11 are rolled on the first roll you win, but if a 2,3 or 12 are rolled you lose.
But if any other number is produced the program jumps to the while loop and starts spitting out numbers until either a 7 is rolled or you roll the same number you started with.
Here is my program;
Code:
#include<stdio.h>
int main()
{
/*declare*/
int D1;
int D2;
int sum, sum2, point;
printf("Press Any Key To Start");
getchar();
srand(time(0));
D1 = 1 + rand() % 6;
D2 = 1 + rand() % 6;
sum = D1 + D2;
printf("\nRoll: %d\n", sum);
if ( sum == 7)
printf("\nYou Win");
if (sum == 11)
printf("\nYou Win");
if (sum == 2)
printf("\nYou lose");
if (sum == 3)
printf("\nYou lose");
if (sum == 12)
printf("\nYou lose");
point = sum;
while((sum2!=1)&&(sum2!=sum))
{
D1 = 1 + rand() % 6;
D2 = 1 + rand() % 6;
sum2 = D1 + D2;
printf(" \nRoll: %d+%d=%d\n ", D1, D2, sum2);
}
if (sum2 == 7)
{
printf("You lose");
}
else
{
printf("\nyou win");
}
}
Now my problem is when the dice rolls and the first if statement is met it still jumps to the while loop instead of ending the program, and also for some reason the while loop doesnt like the;
Code:
if (sum2 == 7)
printf("You lose");
as when it prints 7 it completly ignores it.
Any ideas?
Thanks for your help in advance.