I wrote a program that allows the user to generate their own poll and tally up the results of the input. At the end, I want the results to be displayed as a horizontal bar graph. Here is what I have so far:
{
//All the variables and strings
string poll;
string a1;
string a2;
string a3;
int a=5;
int x=0;
int y=0;
int z=0;
int b;
int c;
int d;
//Making the poll
cout <<"Welcome to your very own poll generator. Please start by entering a question.\n";
getline(cin, poll);
cout <<"Excellent. Now please enter three possible choices. \n";
cout <<"Choice #1: ";
getline(cin,a1, '\n');
cout <<"And now your second choice. \n";
cout <<"Choice #2: ";
getline(cin,a2, '\n');
cout <<"And now your third choice. \n";
cout <<"Choice #3: ";
getline(cin,a3, '\n');
//Tallying the poll
cout <<"Here is your poll. Start the tally by selecting an answer. \n";
while (a!=0)
{
cout << poll << '\n' << "1. "<< a1 << '\n' << "2. " << a2 << '\n' << "3. " << a3 << '\n' << "(Enter 0 to stop the poll.)" << '\n';
cin >> a;
if (a==1)
{
x++;
cout <<"Thank you for your time. Next person please. \n";
continue;
}
elseif (a==2)
{
y++;
cout <<"Thank you for your time. Next person please. \n";
continue;
}
elseif (a==3)
{
z++;
cout <<"Thank you for your time. Next person please. \n";
continue;
}
/*Results of the poll. I tried to take a crack at it but I don't know how to repeat the asterisk so that they go horizontally.*/
elseif (a==0)
{
cout <<"Here are the results of your poll: \n";
cout <<"1 * = 1 vote. \n";
cout << a1 << '\n';
for (b=0;b!=x;b++)
{
cout << "* \n";
}
cout << a2 << '\n';
for (c=0;c!=y;c++)
{
cout << "* \n";
}
cout << a3 << '\n';
for (d=0;d!=z;d++)
{
cout << "* \n";
}
}
else
{
cout <<"I'm sorry, that was not a viable answer. Please try again. \n";
continue;
}
}
}