Question

I made a mini dice game in C and for some reason i cant run my...

I made a mini dice game in C and for some reason i cant run my code. It's not showing me any errors when i compile. Help?

#include <stdio.h> //I/O
#include <stdlib.h> //rand() random number generator
#include <time.h> // time(NULL) seconds since 1 January 1970. time for random generator

void delay() //dramatic pause
{
int ms = 1000;
clock_t time = clock();
while(clock() < time + ms);
}

int throwDice()
{
static int initialized = 0;
int number;
if(!initialized)
{
srand(time(NULL));
initialized=1;
}
number=rand()%6+1;
return number;
}

int main()
{
int humanWins=0, computerWins=0, humanToss, computerToss;
int numberOfTurns;
printf("Enter number of turns: ");
scanf("%d", numberOfTurns);
int turn;
for(turn=1; turn<=numberOfTurns; turn++)
{
char enter =0;
printf("\t\tTurn # %d\n", turn);
printf("\tPress enter to throw the dice.\n Rolling dice...");
printf("\tHUMAN\t||\tCOMPUTER");
do
{
//delay();
while(enter!= 'r'&&enter!='\n')
enter=getchar();
humanToss= throwDice();
computerToss= throwDice();

if(humanToss > computerToss)
{
humanWins++;
printf("\t %d \t||\t Human wins this round!",1,0);
}
else if(computerToss > humanToss)
{
computerWins++;
printf("\t %d \t||\t %d Computer wins this round!",0,1);
}
else if(humanToss == computerToss)
{
printf("\t\t\t ROUND WAS A TIE!!... Re-rolling dice...");
}
}while(humanToss==computerToss);
}
printf("The winner is..... ");
delay();
if(humanToss > computerToss)
printf("HUMAN!");
else
printf("COMPUTER! loser!");

return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

you didn't put ambracent symbol(&) while reading turn variable.you definitely put that.

Code:

#include <stdio.h> //I/O
#include <stdlib.h> //rand() random number generator
#include <time.h> // time(NULL) seconds since 1 January 1970. time for random generator

void delay() //dramatic pause
{
int ms = 1000;
clock_t time = clock();
while(clock() < time + ms);
}

int throwDice()
{
static int initialized = 0;
int number;
if(!initialized)
{
srand(time(NULL));
initialized=1;
}
number=rand()%6+1;
return number;
}

int main()
{
int humanWins=0, computerWins=0, humanToss, computerToss;
int numberOfTurns;
printf("Enter number of turns: ");
scanf("%d",&numberOfTurns);
int turn;
for(turn=1; turn<=numberOfTurns; turn++)
{
char enter =0;
printf("\t\tTurn # %d\n", turn);
printf("\tPress enter to throw the dice.\n Rolling dice...");
printf("\tHUMAN\t||\tCOMPUTER");
do
{
//delay();
while(enter!= 'r'&&enter!='\n')
enter=getchar();
humanToss= throwDice();
computerToss= throwDice();

if(humanToss > computerToss)
{
humanWins++;
printf("\t %d \t||\t Human wins this round!",1,0);
}
else if(computerToss > humanToss)
{
computerWins++;
printf("\t %d \t||\t %d Computer wins this round!",0,1);
}
else if(humanToss == computerToss)
{
printf("\t\t\t ROUND WAS A TIE!!... Re-rolling dice...");
}
}while(humanToss==computerToss);
}
printf("The winner is..... ");
delay();
if(humanToss > computerToss)
printf("HUMAN!");
else
printf("COMPUTER! loser!");

return 0;
}

Add a comment
Know the answer?
Add Answer to:
I made a mini dice game in C and for some reason i cant run my...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT