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.

53 lines
1.2 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int gib_zufallszahl() {
  5. srand(time(NULL));
  6. int zahl = rand() % 100 + 1;
  7. return zahl;
  8. }
  9. void leistung(int versuch, int leistung_toll, int leistung_ok) {
  10. if (versuch <= leistung_toll) {
  11. printf("Tolle Leistung!");
  12. }
  13. else if (versuch <= leistung_ok) {
  14. printf("Sehr durchschnittliche Leistung!");
  15. }
  16. else {
  17. printf("Miese Leistung!");
  18. }
  19. }
  20. void run_zahlenraten() {
  21. int zahl = gib_zufallszahl();
  22. int leistung_toll = 3;
  23. int leistung_ok = 7;
  24. int versuch = 0;
  25. int i = 0;
  26. int vermutung;
  27. 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");
  28. while (i != 1) {
  29. printf("Vermutung: ");
  30. scanf("%d", &vermutung);
  31. versuch++;
  32. if (vermutung == zahl) {
  33. printf("Richtig! Du hast die Zahl in %d Versuchen erraten.\n", versuch);
  34. leistung(versuch, leistung_toll, leistung_ok);
  35. break;
  36. }
  37. else if (vermutung < zahl) {
  38. printf("hoeher!\n");
  39. }
  40. else {
  41. printf("niedriger!\n");
  42. }
  43. }
  44. }