Ok, also ich bin neu, also bitte bitte mit mir. Ich arbeite an einem einfachen Quiz-Spiel, und nur zum Testen habe ich diesen kleinen Code erstellt, um sicherzustellen, dass er richtig funktioniert.Trivia Game loop und bekommen Linie Probleme
// Trivia game for one player. Player will choose a category and program
// will ask you questions within set category. Correct answers are
// worth 5 points and incorrect answers are worth only 2.5 points.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
float score = 0;
string name, question, ans1, ans2, ans3, ans4;
char ans, correct;
ifstream history;
history.open("History.txt");
while (!history.eof())
{
getline(history, question);
cout << question << '\n';
getline(history, ans1);
cout << ans1 << '\n';
getline(history, ans2);
cout << ans2 << '\n';
getline(history, ans3);
cout << ans3 << '\n';
getline(history, ans4);
cout << ans4 << '\n';
history >> correct;
cout << "Enter your answer: ";
cin >> ans;
if (ans = correct)
{
cout << "You are correct!\n";
cout << "5 Points awarded...\n";
score = score + 5;
}
else
{
cout << "Wrong!\n";
cout << "2.5 Points awarded...\n";
score = score + 2.5;
}
}
}
History.txt sieht aus wie ....
What was the first Tudor monarch in England?
A. Henry V
B. Edward IV
C. Henry VII
D. Edmund
C
The Kingdom of Joseon was founded in 1392 in what country?
A. England
B. Isreal
C. China
D. Korea
D
The Spanish Civil War began in what year?
A. 1936
B. 1874
C. 1920
D. 1948
A
So passiert, was ist es liest und gibt die erste Frage und Antworten für den nächsten Satz richtig, dann nur zu C geht dann zu B, und so weiter. Es zählt auch jede Antwort des Benutzers als korrekt. Was mache ich falsch?
Vielen Dank für die Antwort! Das macht vollkommen Sinn. – Brice
Wenn Sie sehen, warum die ersten 4 Zeilen richtig gelesen werden, dann lese ich gemischte Zeilen? Er gibt die erste Frage und 4 Antwortmöglichkeiten perfekt aus, dann macht der nächste nur die Frage und 3 Antworten mit der richtigen Antwort aus history.txt – Brice