So i want to make a quiz program with structs. I have the question, options and the answer in a struct. But i have multiple questions(structs) so i wrote a function to nicely format the input and output. But seems like it doesn't work because i can't use variable struct in functions.
Here's the code:
#include <iostream>
#include <string>
using namespace std;
struct q0{
string question = "Which sea animal has a horn?";
string arr[3] = {"Dolphin", "Clownfish", "Narwhal"};
int correctAnswer = 3;
};
struct q1{
string question = "What is the biggest animal in the world?";
string arr[3] = {"Blue Whale", "Elephant", "Great White Shark"};
int correctAnswer = 1;
};
void quiz(struct q){
cout<<q.question<<endl;
for(int i = 0; i<3; i++){
cout<<i+1<<". "<<q.arr[i]<<endl;
}
int answer;
cin>>answer;
(answer == q.correctAnswer) ? cout<<"Correct\n"<<endl : cout<<"Inorrect\n"<<endl;
}
int main(){
quiz(q0);
quiz(q1);
}