Alright, this has been driving me batty for a while now. I've been trying to make a simple die-rolling game for sometime now, I think I have the If Else statements down pat but it isn't reading correctly...
Help?
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void) {
int ans;
int i;
printf("Care to play a game? The rules are simple: Two 20-sided die is rolled.\n");
printf("If your die rolls 1, you lose.\n");
printf("But if yours rolls 20, you win.\n");
printf("Anything between? Re-roll!\n");
printf("You may only re-roll ten times!\n");
srand(time(NULL));
for (i = 1; i <= 20; i++) {
printf("The Die rolled a %d.\n", (rand() % 20));
if ( rand() > 20 && rand() < 2 ) {
printf("Re-roll? (Y/N)?");
scanf("%d", &ans);
while (ans == 'Y' || ans == 'y');
}
else if (rand() == 1 )
{
printf("You rolled a 1. YOU LOSE!\n");
return(0);
}
else ( rand() == 20);{
printf("You rolled 20!! YOU WIN!\n");
}
}
return(0);
}