Help using parallel arrays

The code that i have so far was used for the first part of my assignment. Now for the second part I have to not only prompt the user for one question from a .txt file but all the questions. Here are the instructions.
Use parallel arrays to read all of the questions from the file
You may assume that the maximum number of questions/answer pairs will be 10
Note that when you read the first integer, the read only consumes the number. The newline character still needs to be read, so you’ll still need to do a getline() after reading the number of cards before reading the questions/answers.
Loop through the questions twice. The first time present each question and prompt for the answer. Give the user up to 3 chances like the first part of this assignment.
You’ll need to remember which questions are answered correctly (I suggest using another parallel array)
After each question has been asked, loop again through the questions. But this time, only ask the questions that were answered incorrectly on the first pass.
After looping through the questions 2 times, print a list of answers that were never entered correctly (one per line). Print “Study:” before the list of answers (even if the user got them all correct, because it is always a good reminder to Study)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

enum UserStatus { ANSWERING, INCORRECT, CORRECT };
/*
main - logic to read from file and prompt user for answer

return: status
*/
int main()
{
	
	UserStatus status;
	ifstream inputFile;
	string fName;
	string question;
	string answer;
	string junk;
	string userinput;

	cout << "File?" << " ";
	getline(cin, fName);
	inputFile.open(fName);

	getline(inputFile, junk);
	getline(inputFile, question);
	getline(inputFile, answer);

	int counter = 0;
	status = ANSWERING;

	while (status == ANSWERING)
	{
		cout << question << "? ";
		getline(cin, userinput);
		for (int i = 0; i < userinput.length(); i++) {
			userinput[i] = tolower(userinput[i]);
		}
		if (userinput == answer)
		{
			status = CORRECT;
		}
		else if (userinput != answer && counter == 2)
		{
			status = INCORRECT;
			counter++;
		}
		else if (userinput != answer && counter < 2)
		{
			status = ANSWERING;
			counter++;
		}

		switch (status)
		{
		case ANSWERING:
			cout << "Try Again" << endl;
			break;
		case CORRECT:
			cout << "Yay!" << endl;
			break;
		case INCORRECT:
			cout << "Sorry it's small fry" << endl;
			break;
		}
	}
	cin.ignore(100, '\n');
	cin.get();
	return 0;


The text file contains 4 questions and 4 answers, and the first line of the .txt file is the number 4. Can someone help me get started with this?
Last edited on
closed account (E0p9LyTq)
Could you please post the data file here? It would make it easier for us so we can use the same data you need to use.
Yes, this is the exact format of the .txt file.
Line 2 is the first question and line 3 is the answer and it follows that format.

4
child
small fry
happy
tickled pink
mock
poke fun at
dough puncher
baker
closed account (E0p9LyTq)
Now the big question. Are you allowed to use std::vectors, or another STL container like a std::map, or must you use C style arrays to hold the data in what the instructions call parallel arrays?
Last edited on
We have not learned about vectors yet at all so I am going to assume C style arrays.
Topic archived. No new replies allowed.