// A Modified Snap game
// The user will input numbers one at a time
// The program will remember previous input from the user
// If the current input matches any previous, the program will say "Snap!"
// Marc Chee (marc.chee@unsw.edu.au) 14/3/2019, modified June 2019

#include <stdio.h>

#define NUM_TURNS 10

int main (void) {
    int prevNums[NUM_TURNS] = {0};

    printf("Welcome to my game of Snap!\n");
    printf("You can type in any number until %d turns are over.\n", NUM_TURNS);
    printf("If I've seen that number before, I will say SNAP!\n");

    // the main game loop. Each turn of the game is one iteration
    int i = 0;
    while (i < NUM_TURNS) {
        printf("Please type in a number: ");
        int input;
        scanf("%d", &input);
        prevNums[i] = input;
        i++;
    }
    return 0;
}

Resource created Tuesday 25 June 2019, 08:39:12 PM, last modified Tuesday 25 June 2019, 10:03:45 PM.

file: snapLec.c


Back to top

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