Code:
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int i;
int count;
int j;
srand(time(NULL));
int r = (rand()%250)+50;
printf("+_+_+_+_+_Guess My Weight_+_+_+_+_+\n\n Enter your weight as an integer between 50-200:\n");
scanf("%i", &i);
if(i<50 || i>250)
{
printf("Invalid input!\n");
}
if(i>=50 || i<=250)
{
if(i>=r-10 && i<=r+10)
{
printf("I guessed %i, which is within 10 pounds of your weight! Sorry, no teddy bear this time.\n", r);
}
else
{
printf("I guessed %i, which is not even close to your weight.\n\n You win a teddy bear!!\n\n", r);
count++;
}
}
printf("Do you want me to try again? (Enter: 1 for Yes, 0 for No)");
scanf("%i", &j);
while(j == 1)
{
printf("Enter your weight as an integer between 50-200:\n");
scanf("%i", &i);
if(i<50 || i>250)
{
printf("Invalid input!\n");
}
if(i>=50 || i<=250)
{
if(i>=r-10 && i<=r+10)
{
printf("I guessed %i, which is within 10 pounds of your weight! Sorry, no teddy bear this time.\n", r);
}
else
{
printf("I guessed %i, which is not even close to your weight.\n\n You win a teddy bear!!\n\n", r);
count++;
}
}
printf("Do you want me to try again? (Enter: 1 for Yes, 0 for No)\n");
scanf("%i", &j);
}
printf("You won %i teddy bears!\n", i);
return 0;
}