Guessing the number program Advice

Have to make a Guessing Game Program and been stuck for a bit cant figure out my next step I have to give the user 10 tries/guesses to guess a random generated number.

#include <stdio.h>
void main ()
{
char icode;
int index;
int number;
int guess;
for(; ;)
{
printf("Welcome to the Guessing Game\n");
printf("please press A to play\n or Q to Quit\n");
scanf("%c", &icode);
if(icode =='A' || icode =='a')
{
number = rand() % 100+1;
for(index =0; index < 10; index++)
{
printf("Please enter a number from 1-100,\nYou have a maximum of 10 guesses\nGood Luck\n");

scanf("%d", &guess);
if (guess < number)
{
printf("My number is higher.\n Please guess again.");
}

elseif (guess > number);
{
printf("My number is lower.\n Please guess again.");

}
else
{

printf("Correct!!! It only took you #%d.",index);
}

} //ENDIF
} //ENDFOR

{
if
count == 10 && !

else
{
if(icode =='Q' || icode =='q')
}


Looks like you're already there! After fixing your small syntax errors the game worked out of the box for me. just change elseif to else if, get rid of the ; at the end of that line, replace the last several lines with enough closing brackets to finish your loop, and if you're compiling in c++ change your void main to int main- life should be good :D

You're very very close.
thx apperciate it but it turns out the code kept crashing for me so i decided to redo it do you think you could revise it give me some pointers because im stuck once again.

#include <time.h>
void main ()
{
char icode;
int number;
int guess;
int i=0;
const int GUESSES=10;
for(; ;)
{
printf("Welcome To The Guessing Game\n");
printf("Please press A to Play\nor Q to Quit");
scanf("%c", &icode);
if(icode != 'A' && icode != 'a')
if(icode != 'Q' && icode != 'q')
{
number = rand() % 100+1;
for(int i = 0; i < GUESESS; ++i)
{
printf("Please enter a number from 1-100,\nYou have a maximum of 10 guesses\nGood Luck.");
scanf("%d", &guess);
++i;
if (guess < number)break;
{
printf("My number is higher.\nPlease guess again.");
}
else if (guess > number) break;
++i;
{
printf("My number is lower.\nPlease guess again.");
}
else
{
printf("Correct!!!! It only took you" i "GUESSES.");
CorrectGuess = 1
}
}
if i == 10 &&!CorrectGuess
{
printf("You Lose. The number was" number);
}
}
}








Topic archived. No new replies allowed.