Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//at the end of the program, the word \'response is shown error. could you help

ID: 3738340 • Letter: #

Question

//at the end of the program, the word 'response is shown error. could you help me what is the problem.

#include <iostream>

#include <fstream>

#include <stdlib.h>

#include <algorithm>

#include <cstring>

#include <string>

#include <ctime>

#define MAXSIZE 100

using namespace std;

struct response {

string resp[MAXSIZE];

string type[MAXSIZE];

int n;

}res;

int readResponses();

void playGame();

void addResponses(int);

void printResponses(int);

void printResponsesType(int);

int main()

{

char ch = 'y';

int numlines;

string question;

do

{

cout << "--------------------------------" << endl;

cout << " Menu";

cout << " --------------------------------" << endl;

cout << " A. Read responses from a file" <<

" B. Play Magic Eight Ball" <<

" C. write responses to the file" <<

" D. Print out responses and categories alphabetically" <<

" E. Exit (upper case E)" <<

" Enter your choice: ";

cin >> ch;

switch (ch) {

case 'a': case 'A':

numlines = readResponses();

break;

case 'b': case 'B':

playGame();

break;

case 'c': case 'C':

addResponses(numlines);

break;

case 'd': case 'D':

printResponses(numlines);

break;

case 'e': case 'E':

break;

default:

cout << " Invalid choice";

break;

}

} while (ch != 'E');

}

int readResponses()

{

ifstream read;

string responses[MAXSIZE];

int numlines = 0;

string line;

int i = 0;

read.open("Responses.txt");

while (getline(read, line))

{

++numlines;

res.resp[i] = line;

i++;

}

cout << "Responses are read" << endl << endl;

read.close();

return numlines;

}

void playGame()

{

string question;

srand(time(NULL));

string answer;

cin.ignore();

cout << "Enter your question: ";

getline(cin, question);

int x = rand() % (20 - 1) + 1;

answer = res.resp[x];

for (int i = 0; i < answer.length(); i++)

cout << answer[i + 1];

cout << endl << endl;

}

void addResponses(int numlines)

{

string line;

int x = numlines + 1;

cin.ignore();

cout << "Write your response: ";

getline(cin, line);

res.resp[x] = line;

numlines++;

ofstream write("Responses.txt");

if (write)

{

write << line << " ";

write.close();

}

cout << "your response is added" << endl << endl;

}

void printResponses(int numlines)

{

ifstream read;

string responses[MAXSIZE];

string line, str;

int i = 0;

read.open("Responses.txt");

while (getline(read, line))

{

str = line;

for (int i = 0; i < str.length(); i++)

cout << str[i + 1];

cout << endl;

}

cout << endl;

read.close();

}

void printResponsesType(int numlines)

{

string str, str1;

ifstream read;

read.open("Responses.txt");

int i = 0, num = 0;

while (getline(read, str))

{

++num;

res.type[i] = str;

i++;

}

cout << " responses in alphabetical order" << endl;

cout << "--------------------------------" << endl;

cout << endl;

read.close();

}

void printResponse(const int last, response organize[]) // prints responses in alphabetical order

{

int maxElement;

int index;

if (last != 0)

{

for (maxElement = last - 1; maxElement > 0; maxElement--)

{

for (index = 0; index < maxElement; index++)

{

if (organize[index].responses > organize[index + 1].responses)

{

swap(organize[index].responses, organize[index + 1].responses);

swap(organize[index].type, organize[index + 1].type);

}//if

}//for

}//for

}

else

cout << "No input please read an input file using option a ";

}

Explanation / Answer

=> organize[index].response > organize[index + 1].response

Here is the problem, response is the name of structure its not a member of struct