# Answer to Question #15366 in C++ for Mandy

Question #15366
Ms Angelina Barnard is the English teacher at Royden High. She shows the movie &ldquo;Gone with the wind&rdquo; to three separate groups of pupils. After each session every pupil who attended the show has to indicate whether he or she found Scarlett (indicated by S) or Rhett (indicated by R) or any other character (indicated by any character except S or R) the most interesting character in the movie. We need a C++ program to count the votes for each of the two main characters and the votes for all the other characters together. Then the three totals have to be displayed. The program has the following structure: 90 &middot; The three totals are initialised to 0. &middot; Now follows a for loop going from 1 to the number of sessions (namely 3). &middot; Inside the loop a prompting message is displayed asking the user to enter the number of pupils who attended the specific session. &middot; Inside this first for loop is another for loop. This loop goes from 1 to the number of pupils that attended the session.
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
int n = 0;
int totals;
for (int i = 0; i < 3; i++)
& for (int j = 0; j < 3; j++)
& totals[i][j] = 0;

for (int i = 0; i < 3; i++) {
& cout << "Enter the number of pupils who attended the session " << i + 1
& lt;< ": ";
& cin >> n;
& for (int j = 0; j < n; j++) {
& cout << "Please indicate whether pupil " << j + 1
& lt;< " found (S, R or any other character): ";
& char c = 'a';
& cin >> c;
& if (c == 'S')
& totals[i]++;
& else if (c == 'R')
& totals[i]++;
& else
& totals[i]++;
& }
}
cout << endl << endl;
cout << setw(12) << "Session" << setw(12) << "Scarlett" << setw(12)
& lt;< "Rhett" << setw(12) << "other" << endl;
for (int i = 0; i < 3; i++)
& cout << setw(12) << i + 1 << setw(12) << totals[i] << setw(12)
& lt;< totals[i] << setw(12) << totals[i] << endl;
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!