/* File: guess.c (Improvement to the original guess.c)
Programmer: Tep Dobry
login: tep
Date:
Mod :
*/
/* This module is responsible for overseeing the entire program; invoking
the other modules as appropriate. It is the module allowing the
user to play the game repeatedly.
The game has been improved to keep track of wins and losses.
*/
#include <stdio.h>
#include "guess.h"
#include "play.h"
#include "tfdef.h"
#define DEBUG
main()
{ int keep_playing = TRUE; /* do we keep playing? initially true. */
int hidden_number; /* the picked random number */
int wins, losses; /* count of wins and loses */
/* Introduce the game */
printf("\n\n\t\tWelcome to the Guessing Game\n");
/* Initialize counts */
wins = losses = 0;
/* While the player wants to keep playing */
while( keep_playing )
{ /* pick a random number */
hidden_number = PICK(START,STOP);
/* introduce the play */
printf("\nI'm thinking of a number between %d "
"and %d\nCan you guess it?\n\n",START,STOP);
#ifdef DEBUG
printf("debug:main:the pick is %d\n",hidden_number);
#endif
/* play the game */
if( play(hidden_number) == WIN) wins = wins + 1;
else losses = losses + 1;
/* ask the player if they want to continue */
printf("\nDo you want to play again?\n");
printf("(1 for yes, 0 for no): ");
scanf("%d", &keep_playing);
}
/* say goodbye */
printf("\nYou won %d times out of %d\n",wins, wins+losses);
printf("\nThanks for the game.... bye...\n");
}