How to count choosen answers ?

HI guys, I have been learning c++ from book called "jumping into c++" and and the end of one part, there was a task, and it goes like this

Write a program that provides the option of tallying up the results of a poll with 3 possible
values. The first input to the program is the poll question; the next three inputs are the possible
answers. The first answer is indicated by 1, the second by 2, the third by 3. The answers are
tallied until a 0 is entered. The program should then show the results of the poll—try making a
bar graph that shows the results properly scaled to fit on your screen no matter how many
results were entered.



This is my code so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream> 
#include <string> 

using namespace std; 

int main (){ 

string question,ans_one,ans_two,ans_three; 


cout<<"Please insert your question"<<"\n"; 
getline (cin, question, '\n'); 

cout<<"Insert all possible answers"<<"\n"; 

getline (cin, ans_one, '\n'); 
getline (cin, ans_two, '\n'); 
getline (cin, ans_three, '\n'); 





}


The problem is, I don't know how to make program "follow" how many times has some answer been choosen. How would you do it ?

Thanks in advance.
You'll need to declare variables to store the number of times each answer has been chosen. Each time an answer is chosen, increment the value of the appropriate variable.
Last edited on
Topic archived. No new replies allowed.