You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int gib_zufallszahl() { srand(time(NULL)); int zahl = rand() % 100 + 1; return zahl; }
void leistung(int versuch, int leistung_toll, int leistung_ok) { if (versuch <= leistung_toll) { printf("Tolle Leistung!"); } else if (versuch <= leistung_ok) { printf("Sehr durchschnittliche Leistung!"); } else { printf("Miese Leistung!"); } }
void run_zahlenraten() {
int zahl = gib_zufallszahl();
int leistung_toll = 3; int leistung_ok = 7; int versuch = 0; int i = 0; int vermutung;
printf("Versuchen Sie eine Zahl von 1 bis 100 zu erraten. \nNach jedem Fehlversuch gibt es einen Tipp, \nob die gesuchte Zahl hoeher oder niedriger \nals die Eingabe ist.\n");
while (i != 1) {
printf("Vermutung: "); scanf("%d", &vermutung);
versuch++;
if (vermutung == zahl) { printf("Richtig! Du hast die Zahl in %d Versuchen erraten.\n", versuch); leistung(versuch, leistung_toll, leistung_ok); break; } else if (vermutung < zahl) { printf("hoeher!\n"); } else { printf("niedriger!\n"); } } }
|