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.

110 lines
1.5 KiB

1 year ago
1 year ago
1 year ago
  1. //1
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include "Mathe.h"
  6. //2
  7. void initialisiereZufallsgenerator();
  8. //3
  9. int generiereZufallszahl(int min, int max);
  10. //4
  11. char generiereZufallsOperator();
  12. //5
  13. int addiere(int zahl1, int zahl2);
  14. //6
  15. int subtrahiere(int zahl1, int zahl2);
  16. //7
  17. int multipliziere(int zahl1, int zahl2);
  18. //8
  19. int dividiere(int zahl1, int zahl2);
  20. //9
  21. int berechneErgebnis(int zahl1, int zahl2, char operator);
  22. //10
  23. void spieleRunde(int schwierigkeitsgrad);
  24. //11
  25. void zeigeAnleitung();
  26. //12
  27. void zeigeHighscore(int punkte);
  28. //13
  29. int holeSpielerAntwort();
  30. //14
  31. void bewerteAntwort(int spielerAntwort, int ergebnis, int* punkte);
  32. //15
  33. void zeigeRundenEnde(int punkte);
  34. //16
  35. void zeigeAuswahl(const char* text);
  36. //17
  37. void initialisiereZufallsgenerator() {
  38. srand(time(NULL));
  39. }
  40. //18
  41. int generiereZufallszahl(int min, int max) {
  42. return min + (int)((double)rand() / (RAND_MAX + 1) * (max - min + 1));
  43. }
  44. //19
  45. char generiereZufallsOperator() {
  46. char operatoren[] = {'+', '-', '*', '/'};
  47. int index = rand() % 4;
  48. return operatoren[index];
  49. }
  50. //20
  51. int berechneErgebnis(int zahl1, int zahl2, char operator) {
  52. switch (operator) {
  53. case '+':
  54. return addiere(zahl1, zahl2);
  55. case '-':
  56. return subtrahiere(zahl1, zahl2);
  57. case '*':
  58. return multipliziere(zahl1, zahl2);
  59. case '/':
  60. return dividiere(zahl1, zahl2);
  61. default:
  62. return 0;
  63. }
  64. }