// Dice Checker
// Take two dice worth of input from a user
// add them together and check them against
// a target number.
// Report back success or failure.
// Lecture demo by Marc Chee, September 2020
// (cs1511@cse.unsw.edu.au)
#include <stdio.h>
#define TARGET_VALUE 7
int main(void) {
// take input from user about the two dice
int dieOne;
int dieTwo;
// Ask for and read input about dieOne
printf("Please type in the value of the first die: ");
scanf("%d", &dieOne);
// Ask for and read input about dieTwo
printf("Please type in the value of the second die: ");
scanf("%d", &dieTwo);
// Calculate and report Total
int total = dieOne + dieTwo;
printf("Total rolled is: %d\n", total);
// Check against the secret target value
if (total >= TARGET_VALUE) {
// success
printf("Dice check was successful!\n");
} else {
// failure
printf("Dice check failed . . .\n");
}
return 0;
}
Resource created Friday 18 September 2020, 01:58:17 PM.
file: diceCheck.c