我正在尝试使用cout
和cin
进行基本测验,我被困在这里:
#include <iostream>
using namespace std;
char askQuestion (int questionNumber, char* question, char* optionA, char* optionB, char* optionC) {
char answer;
cout << questionNumber << ".)" << question << "\n";
cout << optionA << "\n";
cout << optionB << "\n";
cout << optionC << "\n";
cin >> answer;
return answer;
}
int main()
{
char answer1;
char answer2;
char questionNumber;
questionNumber = 1;
answer1 = askQuestion(questionNumber, "Who is the Big Red Dog?", "A.)Milo", "B.)Clifford", "C.)Jack");
return 0;
}
你的意思是输出答案吗?...
#include <iostream>
using namespace std;
char askQuestion(int questionNumber, char* question, char* optionA, char* optionB, char* optionC) {
char answer{};
cout << questionNumber << ".)" << question << "\n";
cout << optionA << "\n";
cout << optionB << "\n";
cout << optionC << "\n";
cin >> answer;
return answer;
}
int main()
{
char answer1;
char answer2;
char questionNumber;
questionNumber = 1;
answer1 = askQuestion(questionNumber, "Who is the Big Red Dog?", "A.)Milo", "B.)Clifford", "C.)Jack");
(answer1 == 'B') ? cout << "CORRECT!!!" : cout << "INCORRECT!!!";
cout << endl;
return 0;
}