/* * guessprime3.c - a C version of our simple bash demo program guessprime.sh * (simple replacement for the bash program). Users guess an integer to see if * it matches a predetermined number (hard coded to 31 here). * This version moves readGuess after main * * input: a guessed integer * output: whether guessed integer matches 31 * * compile: gcc -o guessprime guessprime3.c * usage: ./guessprime * * Tim Pierson, Fall 2022, based on (or exactly copied from) prior term code from David Kotz * CS 50, Fall 2022 * */ #include int readGuess(); // declaration of a function prototype // Main function - ask for a guess, quit if it matches the answer and keep asking otherwise int main(int argc, char *argv[]) { const int answer = 31; int guess; guess = readGuess(); while (guess != answer) { printf("Wrong! try again\n"); guess = readGuess(); } return 0; // exit status } // Ask for and read a guess // function actual *definition* int readGuess() { int guess; printf("Enter a prime between 1-100: "); scanf("%d", &guess); return guess; }