Hi guys I am completely new to c++ and i decided to work my way through - Jumping into c++. I am currently up to chapter 5 and have found myself stumped a couple of times along the way.
My current predicament is practice problem 7 in chapter 5: 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 manyresults were entered.
My code is as follows, thanks for your help in advance.
Code:#include <iostream> #include <string> using namespace std; int main() { int answer; int a = 0; int b = 0; int c = 0; do { cout << "Who is the best?" << "\n" << "1. Zach" << "\n" << "2. Michelle" << "\n" << "3. Jack" << "\n"; cin >> answer; if (answer == 1) { a++; } else if (answer == 2) { b++; } else if (answer == 3) { c++; } else if (answer == 0) { cout << "Zach = " << a << "\n" << "Michelle = " << b << "\n" << "Jack = " << c << "\n"; } else { cout << "Who is the best?" << "\n" << "1. Zach" << "\n" << "2. Michelle" << "\n" << "3. Jack" << "\n"; cin >> answer; } } while (answer < 0); }