dimanche 7 juin 2020

Else and If statements C

I just started coding in C, and I can't figure out how to add the idea of doubles, where the program detects when a player has rolled the same number on both dies and report it as critical success, critical failure or critical tie. This is a simple dice checker:

//Dice Checker Demo 
#include <stdio.h> 

#define SECRET_TARGET 7

int main(void) {
    //read in and store the value of the first die 
    printf("Welcome to Dicechecker!\n"); 
    int dieOne; 
    printf("Please input the value of the first die: ");
    scanf("%d", &dieOne); 

    int dieTwo;
    printf("Please input the value of the second die: ");
    scanf("%d", &dieTwo);

    int total = dieOne + dieTwo;
    printf("The total of the dice roll is currently: %d\n", total);

    if (total > SECRET_TARGET) {
        printf("Skill Roll Successful, Congratulations\n");
    } else if (total == SECRET_TARGET) {
        printf("Close, but not close enough, try again please\n");
    } else if (dieOne == dieTwo && total > SECRET_TARGET) {
        printf("Critical Success! Large Applause\n");
    } else {
        printf("Skill Roll failed, Try Again\n");
    }    

    return 0; 
}

Aucun commentaire:

Enregistrer un commentaire