Hi all,
I am a real newbie to the forum and to C programming. I just started learning a week ago. This is my first try at a program and I have something wrong and I can not figure it out. I know it will be something simple but I can not find it.
would you please take a look at it and give some pointers on what I am doing wrong. Beside it being slopy code, and probably not to efficient. Why will it not loop ?
Here is my code:
Code:
/* This is a guessing game. You try to guess what the magic number is.
You get 10 tries or guess the right number before the game terminates.
Then the game terminates and tell you how may right and wrong answers
that you had. */
#include<stdio.h>
int main(void)
{
int right ; // Declare the variables
int wrong ;
int magicnum =123;
int guess ;
int tries ;
int i = 1;
printf(" Try to guess the magic number\n");
for(i=0 ; i<11 && guess!=magicnum ; i++);
{
printf(" Enter your guess.\n");
scanf("%d.\n", &guess);
if(guess==magicnum)
{
tries=1;
printf("Right !\n");
printf(" It took %d try.\n", tries );
right++;
}
if(guess > magicnum)
{
printf("Try Again.\n");
printf(" Your number was too high.");
wrong++;
tries++;
}
else
{
printf("Wrong !\n Your number is too low !\n");
wrong++;
tries++;
}
}
printf(" It took %d tries.\n", tries);
printf(" You had %d right and %d wrong !\n", right, wrong);
printf("The program will now terminate !");
return 0;
}