Hello! I'm currently writing a quiz show code but I'm continually getting an error that has me at the end of my wits. This is the error and the function it occurs in:
Error:
QuizShowProj.cpp:272:60: error: cannot convert ‘std::string* {aka std::basic_string<char>*}’ to ‘char*’ for argument ‘2’ to ‘int show_question(std::string (*)[5], char*, int)’
responseStatus[i] = show_question(qArray, aArray, num);
Function:
int play_game(string qArray[AMOUNT][5], string aArray[AMOUNT], int fixedSeed, bool used[AMOUNT], string userName) {
int score = 0;
int responseStatus[6];
int num = 0;
for (int i = 0; i < 6; i++) {
responseStatus[i] = 0;
}
Addon: This is the function used in play_game:
int show_question(string qArray[AMOUNT][5], char aArray[AMOUNT], int count) {
char answer;
char retryAns;
int whatHappened = 0; // If = 1, correct answer. If = 2, incorrect answer, retried and correct. If = 3, skip question. If = 4, incorrect second answer; end.
answer = player_try(qArray, count);
if (answer == aArray[count]) {
cout << "You were right! " << answer << " was the correct choice!" << endl;
whatHappened = 1;
}
else {
cout << "Your answer was incorrect. Would you like a second try? Y/N: " << endl;
cin >> retryAns;
toupper(retryAns);
while (retryAns != 'Y' && retryAns != 'N') {
cout << "Please respond with 'Y' or 'N': ";
cin >> retryAns;
toupper(retryAns);
}
Please edit your posts and add code formatting with [ code] and [ /code] tags (minus the spaces).
Show us what line 272 is. Also, you're using = (assignment) in places where you are meaning to use == (equality test).
Edit: Do you understand the difference between
char array[N];
and
string array[N];
?
The former is an array of individual characters.
The latter is an array of C++ strings (which each hold sequences of characters). You are trying to pass the former as the latter into show_questions.