/* Dice Checker Lecture Demo
   Marc Chee (cs1511@cse.unsw.edu.au), June 2020
   
   This small example will ask the user to input the
   result of two dice rolls.
   It will then check the sum of them against its 
   secret number.
   It will report back: 
       a success (higher or equal)
       a failure (lower)
*/

#include <stdio.h>

#define SECRET_TARGET 7

int main(void) {
    // read in and store the value of the first die
    int dieOne;
    printf("Please input the value of the first die: ");
    scanf("%d", &dieOne);
    
    // read in and store the value of the second die 
    int dieTwo;
    printf("Please input the value of the second die: ");
    scanf("%d", &dieTwo);
    
    int total = dieOne + dieTwo;
    printf("Total of the dice roll is: %d\n", total);
    
    // Check the total against the secret number    
    if (total >= SECRET_TARGET) { // Success
        printf("Success!\n");
    } else { // Failure
        printf("Failure!\n");
    }
    
    return 0;
}

Resource created Thursday 04 June 2020, 06:41:08 PM.

file: diceChecker.c


Back to top

COMP1511 20T2 (Programming Fundamentals) is powered by WebCMS3
CRICOS Provider No. 00098G