For this dice rolling game, I am supposed to count wins and losses rolling two dices at once.
If the sum of the two dice is 7 on the first roll then the player wins. If the first roll is not 7, then the play continues to run until it rolls a number the same as the first roll, then the player wins. If the player does not have a 7 on a first roll but gets 7 before matching the first roll, then the player loses.
The player plays 1000 games and count the wins and losses.
I am not entirely sure of the logic of this programming assignment, but my code execute and returns 0s for both wins and losses.
Can anyone please tell me what went wrong with the code?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rolldice()
{
int num[1000], wins, losses;
srand(time(NULL));
for (int i = 0; i < 1000; i++)
{
int dice1 = (rand() % 6) + 1;
int dice2 = (rand() % 6) + 1;
num[i] = dice1 + dice2;
if (num[0] == 7)
{
wins++;
}
if (num[0] != 7 && num[i] == num[0])
{
wins++;
}
if (num[0] != 7 && num[i] == 7)
{
losses++;
}
return wins, losses;
}
}
int main()
{
int wins, losses;
rolldice();
printf("wins: %d \nlosses: %d", wins, losses);
}