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.
There is probably a much easier way than using the if statements I have but I don't know what else to use. I am unsure what I need to do to tally the results at the end. I'm assuming it's some sort of count algorithm. And I have no idea how to make a bar graph. :{ Help please.
#include <iostream>
usingnamespace std;
int main()
{
while (true)
{
int input;
char riding=1;
char golfing=2;
char reading=3;
char done=0;
cout<<"Please type the name of one of the following options you enjoy the most\n0. Enter done to end poll and see results\n1. Hunting\n2. Fishing\n3. Drinking\n";
cin>>input;
if (input==1)
{
cout<<"You chose riding as the activity you enjoyed the most\n";
}
if(input==2)
{
cout<<"You chose golfing as the activity you enjoyed the most\n";
}
if(input==3)
{
cout<<"You chose reading as the activity you enjoyed the most\n";
}
if (input==0)
{
cout<<"Poll has ended.\n Results:\n";
break;
}
if(input!=0||1||2||3)
{
cout<<"Please enter a valid option\n";
}
}
}
As for tallying, there is nothing to tally yet. your program does not store results of the multiple answers anywhere. Make at least two questions and store results somewhere.