Hey everyone
I'm redesigning the random number guessing game and want to haev a statement that goes on the amount of guesses it took... This is the code I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
int main(int argc, char *argv[]) {
int max_guess = 100, min_guess = 0, rand_num = 0;
int guess = 0, num_of_guesses = 1;
char temp[5];
srand(time(NULL));
if(argc > 1) { /* Test for arguments */
printf("%s: This program uses no arguments.\n", argv[0]);
return 1;
}
rand_num = 1 + rand() % 100;
do {
printf("Please enter your guess: ");
fgets(temp, sizeof(temp), stdin);
sscanf(temp, "%d", &guess);
if(guess < rand_num) {
if(guess <= min_guess && min_guess != 0) {
printf(":: Ignored: Your lowest is already %d ::\n", min_guess);
} else {
min_guess = guess;
++num_of_guesses;
guess = 0;
}
} else if(guess > rand_num) {
if(guess >= max_guess && max_guess != 0)
printf(":: Ignored: Your highest is already %d ::\n", max_guess);
else
max_guess = guess;
++num_of_guesses;
guess =0;
}
printf("Min: %d\tMax: %d\n", min_guess, max_guess);
} while(guess != rand_num);
printf("\n%s You got it in %d guess(s)\n",
num_of_guesses <= 3 ? "Great work." : "At least you finished.",
num_of_guesses);
return 0;
}
What I wanna do is expand the amount of sayings: i.e. if the player guessed between 1 and 3 then have 1 saying, between 4 and 10 have another and another for over 10....
Is this possible?