finished program. Program works, styling could be better lol
This commit is contained in:
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
66
main.c
Normal file
66
main.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int getRandomNumber();
|
||||
int askForRepeat();
|
||||
int running = 1;
|
||||
|
||||
int main()
|
||||
{
|
||||
int limiter = 10;
|
||||
printf("Der Limiter ist momentan %d, auf was willst du ihn setzen? \n", limiter);
|
||||
scanf("%d", &limiter);
|
||||
while (running == 1)
|
||||
{
|
||||
int randomNumber = getRandomNumber(limiter);
|
||||
int versuch = 0;
|
||||
char repeat = 0;
|
||||
printf("Rate eine Zahl zwischen 1 und %d\n", limiter);
|
||||
scanf("%d", &versuch);
|
||||
if (versuch == randomNumber)
|
||||
{
|
||||
printf("Richtig!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Falsch!\n Probieren wir es mit einer anderen Zahl!\n");
|
||||
}
|
||||
|
||||
int repetition = askForRepeat();
|
||||
if (repetition == 1)
|
||||
{
|
||||
running = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
running = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getRandomNumber(int limiter)
|
||||
{
|
||||
return rand() % limiter;
|
||||
}
|
||||
|
||||
int askForRepeat()
|
||||
{
|
||||
char nochmal;
|
||||
printf("Willst du nochmal spielen?\n");
|
||||
scanf("%c", &nochmal);
|
||||
if (nochmal == 'j')
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (nochmal == 'n')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Input konnte nicht gelesen werden\n");
|
||||
return askForRepeat();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user