vendredi 27 décembre 2019

Make a dice rolling game

A normal six-sided dice is thrown six times; the user must guess a number each time the dice is thrown. If the number matches the guess, the user wins a point. Score 4 points to win. I'm working on a project to make a dice throwing game. The goal is to guess the number that the dice is going to land on, and to repeat this loop until the user chooses to exit the program. Currently I'm just working on getting the inital stage to work, but for some reason my dice is coming up with an extremely large number and due to my limited understanding of srand I don't know how to fix it, so any help would be greatly appreciated

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    int runs, correct, correct_guesses, guess;

    srand(time(NULL));
    correct_guesses = 0;

    int roll = ((rand() % 6) + 1);
    printf("Please guess the number the dice will land on\n");
    printf("%d", &roll);
    scanf("%d", &guess);
    {
        switch (guess)
        {
        case '1': correct = 1 == roll; break;
        case '2': correct = 2 == roll; break;
        case '3': correct = 3 == roll; break;
        case '4': correct = 4 == roll; break;
        case '5': correct = 5 == roll; break;
        case '6': correct = 6 == roll; break;
        default: correct = 0; printf("Not a possible outcome\n");
        }
    if (correct)
    {
        printf("You guessed correctly!\n");
    }
    else
        printf("You guessed incorrectly\n");
    }
}



Aucun commentaire:

Enregistrer un commentaire