Question
#include #include #include #include #include int getTheNumberOnTheDice(){ int sum = 0; srand(time(NULL)); sum+= rand() % 6 + 1; sum+= rand() % 6 + 1; return
#include
#include
#include
#include
#include
int getTheNumberOnTheDice(){
int sum = 0;
srand(time(NULL));
sum+= rand() % 6 + 1;
sum+= rand() % 6 + 1;
return sum;
}
void main(){
clrscr();
int ph = 100;
int eh = 100;
int num = 0;
int i = 1;
do {
num = getTheNumberOnTheDice();
printf ("[ Round %d ] -- The number on the dice is %d ", i, num);
if (num < 7) {
ph -= 20;
}
if (num > 6) {
eh -= 20;
}
printf("Player's current health --> %d ", ph);
printf("Enemy's current health --> %d ", eh);
sleep(1);
i++;
} while ((ph > 0) && (eh > 0));
if (ph > eh){
printf("You win ");
} else
printf("You lose ");
getche();
}
Create a simplified and shorter version of this code. ( CODE MUST BE IN C AND TRY TO MAKE WITHOUT USING sleep command and time.h library and unistd.h library )
Original Question was Create 2 dice Game using C Language. When game starts, Player`s health will be 100 & enemy`s health will also be 100. When 2 dice is roll and if sum of these dice is less than 7 then player`s health will be decreases 20 points. Thats mean total health of player will be 80 points. When 2 dice is roll and if sum of these dice is greater than 6 then enemy`s health will be decreases 20 points. That`s means total health of player will be same but the total health of enemy will be 80 points. In the end of program message will be shown either You win or You lose.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started