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.

58 lines
1.4 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. // Erklaerung in separater Funktion um spaeter noch mehr Sprachen hinzuzufuegen
  10. void erklaerung() {
  11. 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");
  12. }
  13. void leistung(int versuch, int leistung_toll, int leistung_ok) {
  14. if (versuch <= leistung_toll) {
  15. printf("Tolle Leistung!");
  16. }
  17. else if (versuch <= leistung_ok) {
  18. printf("Sehr durchschnittliche Leistung!");
  19. }
  20. else {
  21. printf("Miese Leistung!");
  22. }
  23. }
  24. void run_zahlenraten() {
  25. int zahl = gib_zufallszahl();
  26. int leistung_toll = 3;
  27. int leistung_ok = 7;
  28. int versuch = 0;
  29. int i = 0;
  30. int vermutung;
  31. erklaerung();
  32. while (i != 1) {
  33. printf("Vermutung: ");
  34. scanf("%d", &vermutung);
  35. versuch++;
  36. if (vermutung == zahl) {
  37. printf("Richtig! Du hast die Zahl in %d Versuchen erraten.\n", versuch);
  38. leistung(versuch, leistung_toll, leistung_ok);
  39. break;
  40. }
  41. else if (vermutung < zahl) {
  42. printf("hoeher!\n");
  43. }
  44. else {
  45. printf("niedriger!\n");
  46. }
  47. }
  48. }