#include<stdio.h>
#include<stdlib.h>
#include<time.h>
/*This is Guess a Number DOS edition by Stuart Miles*/
int guess(int number, int max);
/*Main function, asks for number pool, outputs some stuff*/
int main()
{
int max, number, end;
srand( time(NULL));
rand();
printf("\t\t\t-----------------\n\t\t\t|guess a number!|\n\t\t\t-----------------\n");
printf("Out of how many numbers would you like to guess?\n\n");
scanf("%d" , &max);
number = (rand() %max);
end = guess(number, max);
printf( "Your final guess was %d. \nThanks for playing.\n\nby Stuart Miles." , end);
return(0);
}
/*guess function, asks for the users guesses and outputs higher/lower clues. Returns the final number*/
int guess(int number, int max)
{
int myguess, i;
i=0;
while( number != myguess )
{
printf( "please select a number\n" );
scanf( "%d" , &myguess);
if(myguess == number)
{
printf( "\n\n------------------\nYou win!\nYou took %d turns.\n" , i+1 );
}
else if( myguess > number)
{
printf( "--The number is lower--\n\n" );
}
else if( myguess < number)
{
printf( "--The number is higher--\n\n");
}
i++;
}
return(myguess);
}