Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- int main()
- {
- std::string poll_question;
- std::string answer1, answer2, answer3;
- int num_answer1 = 0, num_answer2 = 0, num_answer3 = 0;
- int user_input = -1;
- std::cout << "What is the poll question?" << std::endl;
- std::getline(std::cin, poll_question);
- std::cout << "What's the first answer choice?" << std::endl;
- std::getline(std::cin, answer1);
- std::cout << "What's the second answer choice?" << std::endl;
- std::getline(std::cin, answer2);
- std::cout << "What's the third answer choice?" << std::endl;
- std::getline(std::cin, answer3);
- // begin polling
- while (user_input != 0)
- {
- std::cout << poll_question << std::endl;
- std::cout << "Please enter a poll selection (0 to indicate that you're done entering results): \n";
- std::cout << "1: " << answer1 << std::endl;
- std::cout << "2: " << answer2 << std::endl;
- std::cout << "3: " << answer3 << std::endl;
- std::cout << std::endl;
- std::cin >> user_input;
- if (user_input == 1)
- ++num_answer1;
- if (user_input == 2)
- ++num_answer2;
- if (user_input == 3)
- ++num_answer3;
- }
- // done polling, display results
- std::cout << "1: ";
- for (int i = 0; i < num_answer1; i++)
- std::cout << " * ";
- std::cout << std::endl;
- std::cout << "2: ";
- for (int i = 0; i < num_answer2; i++)
- std::cout << " * ";
- std::cout << std::endl;
- std::cout << "3: ";
- for (int i = 0; i < num_answer3; i++)
- std::cout << " * ";
- std::cout << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement