Gast
#2478300
Hallo,
ich habe aus Spass die Aufgabe gefunden und wollte es ausprobieren.
Ich komme aber bei der if Abfrage am Ende nicht so richtig weiter.
Es springt bei der Ja oder Nein Frage raus bevor ich was eingeben kann.
Hat jemand eine idee?
Danke im Voraus!
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
again:
int iSecret, iGuess;
char* answer;
int tries=0;
srand ( time(0) );
iSecret = rand() % 20;
do {
printf("Number: %i \n", iSecret);
printf ("Guess the number (0 to 20): ");
scanf ("%d",&iGuess);
if (iGuess>=iSecret+3)
{
printf ("Too big\n");
//tries++;
}
else if (iGuess==iSecret+2 || iGuess==iSecret+1)
{
printf ("A little big\n");
//tries++;
}
else if (iGuess<=iSecret-3)
{
printf ("Too small\n");
//tries++;
}
else if (iGuess==iSecret-2 || iGuess==iSecret-1)
{
printf ("A little small\n");
//tries++;
}
} while (iSecret!=iGuess);
if(iSecret==iGuess)
{
printf("Congratulations!Do you want to play again? y/n ");
scanf("%c",&answer);
if(answer == 'y' || answer== 'Y')
printf("Congratulations!\n");
//goto again;
else if(answer == 'n' || answer== 'N')
printf("Congratula!\n");
//goto again;// return 0;
}
}