Skip to content

Instantly share code, notes, and snippets.

@JBlond
Last active January 7, 2025 12:49
Show Gist options
  • Save JBlond/c8a9a9fe137c754972bb516cb06475e6 to your computer and use it in GitHub Desktop.
Save JBlond/c8a9a9fe137c754972bb516cb06475e6 to your computer and use it in GitHub Desktop.
number-game
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int myNumber = 0;
int tries = 0;
int zahl = 0;
int main() {
srand((unsigned int) time(0));
myNumber = rand() % 100 + 1;
for (tries = 0; zahl != myNumber; ++tries) {
printf("Bitte gib eine Zahl von 1 bis 100 ein: \n");
scanf_s("%d", &zahl);
if (zahl == myNumber) {
printf("Richtig geraten!!!\n");
printf("Du hast %d Versuche gebraucht. \n", tries);
return 0;
}
else
{
if (zahl < myNumber) {
printf("Deine Zahl ist zu klein\n");
}
else
{
printf("Deine Zahl ist zu gro\xe1\n");
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment