|
|
@ -456,9 +456,89 @@ void displayMenu() { |
|
|
|
printf("Auswahl treffen: "); |
|
|
|
} |
|
|
|
|
|
|
|
int getUserChoice() { |
|
|
|
int choice; |
|
|
|
if (scanf("%d", &choice) != 1) { |
|
|
|
printf("Ungültige Eingabe. Bitte eine Zahl eingeben.\n"); |
|
|
|
// Optional: Hier könntest du die Funktion rekursiv aufrufen oder einen Standardwert zurückgeben. |
|
|
|
} |
|
|
|
return choice; |
|
|
|
} |
|
|
|
|
|
|
|
int getUserChoice() { |
|
|
|
int choice; |
|
|
|
if (scanf("%d", &choice) != 1) { |
|
|
|
printf("Ungültige Eingabe. Bitte eine Zahl eingeben.\n"); |
|
|
|
// Optional: Hier könntest du die Funktion rekursiv aufrufen oder einen Standardwert zurückgeben. |
|
|
|
} |
|
|
|
return choice; |
|
|
|
} |
|
|
|
|
|
|
|
void playGame() { |
|
|
|
int correctAnswers = 0; |
|
|
|
int totalQuestions = 5; // Anzahl der Fragen im Spiel |
|
|
|
|
|
|
|
for (int i = 0; i < totalQuestions; ++i) { |
|
|
|
int num1 = generateRandomNumber(1, 10); |
|
|
|
int num2 = generateRandomNumber(1, 10); |
|
|
|
int operation = generateRandomNumber(1, 8); |
|
|
|
|
|
|
|
int result; |
|
|
|
char operator; |
|
|
|
|
|
|
|
switch (operation) { |
|
|
|
case 1: |
|
|
|
result = addition(num1, num2); |
|
|
|
operator = '+'; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
result = subtraction(num1, num2); |
|
|
|
operator = '-'; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
result = multiplication(num1, num2); |
|
|
|
operator = '*'; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
result = division(num1, num2); |
|
|
|
operator = '/'; |
|
|
|
break; |
|
|
|
case 5: |
|
|
|
result = modulo(num1, num2); |
|
|
|
operator = '%'; |
|
|
|
break; |
|
|
|
case 6: |
|
|
|
result = compare(num1, num2); |
|
|
|
operator = '='; |
|
|
|
break; |
|
|
|
case 7: |
|
|
|
result = exponentiation(num1, num2); |
|
|
|
operator = '^'; |
|
|
|
break; |
|
|
|
case 8: |
|
|
|
result = squareRoot(num1); |
|
|
|
operator= "Wurzel"; |
|
|
|
break; |
|
|
|
default: |
|
|
|
printf("Ungültige Operation.\n"); |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printf("\nFrage %d: Was ist %d %c %d?\n", i + 1, num1, operator, num2); |
|
|
|
|
|
|
|
int userAnswer = getUserAnswer(); |
|
|
|
|
|
|
|
if (userAnswer == result) { |
|
|
|
printf("Richtig!\n"); |
|
|
|
correctAnswers++; |
|
|
|
} else { |
|
|
|
printf("Falsch. Die richtige Antwort ist: %d\n", result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
displayResult(correctAnswers, totalQuestions); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|