I need my program to relate each answer to 1); however, when I use my if statement to keep my program from going above the highest vector index, it ends up repeating the values a
and b
in the 4th question, and the value a
for the fifth question.
How I want my output to look:
First Question: 1)a 2)b 3)c 4)d
Second Question: 1)b 2)c 3)d 4)e
Third Question: 1)c 2)d 3)e 4)a
Fourth Question: 1)d 2)e 3)a 4)b
Fifth Question: 1)e 2)a 3)b 4)c
Actual Output:
First Question: 1)a 2)b 3)c 4)d
Second Question: 1)b 2)c 3)d 4)a
Third Question 1)c 2)a 3)b 4)c
Fourth Question: 1)a 2)b 3)a 4)b
Fifth Question: 1)a 2)a 3)a 4)a
How can I fix my code in order make the output look how I want it to?
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <cmath>
using namespace std;
int main()
{
vector<string> vecQuestions = //vector that will hold all questions
{
"First Question: \n",
"Second Question:\n",
"Third Question\n",
"Fourth Question: \n",
"Fifth Question:\n"
};
vector<string> vecAnswers = // the index of vecAnswers[] correlates to vecAnswers[] //holds all answers
{
"a",
"b",
"c",
"d",
"e"
};
array<int, 4> answer_choices = {{1,2,3,4}}; //sets answer choices
for (unsigned int i =0; i<vecAnswers.size(); i++) //as long as there are questions
{
int answers_index = i;
cout << vecQuestions[i];
for (int x:answer_choices) // for all four values of array answer choices
{
int values_left = vecAnswers.size() - i-1;
if (values_left < answers_index) //attempt to keep from accessing invalid memory from too large of vector size
{
answers_index =0;
}
cout << x << ")" << vecAnswers[answers_index] << " ";
answers_index++;
}
cout <<"\n\n";
}
return 0;
}