Advertisement
AEassa

Untitled

Jul 2nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6.     std::string poll_question;
  7.     std::string answer1, answer2, answer3;
  8.     int num_answer1 = 0, num_answer2 = 0, num_answer3 = 0;
  9.     int user_input = -1;
  10.     std::cout << "What is the poll question?" << std::endl;
  11.     std::getline(std::cin, poll_question);
  12.    
  13.     std::cout << "What's the first answer choice?" << std::endl;
  14.     std::getline(std::cin, answer1);
  15.  
  16.     std::cout << "What's the second answer choice?" << std::endl;
  17.     std::getline(std::cin, answer2);
  18.  
  19.     std::cout << "What's the third answer choice?" << std::endl;
  20.     std::getline(std::cin, answer3);
  21.  
  22.     // begin polling
  23.     while (user_input != 0)
  24.     {
  25.         std::cout << poll_question << std::endl;
  26.         std::cout << "Please enter a poll selection (0 to indicate that you're done entering results): \n";
  27.         std::cout << "1: " << answer1 << std::endl;
  28.         std::cout << "2: " << answer2 << std::endl;
  29.         std::cout << "3: " << answer3 << std::endl;
  30.         std::cout << std::endl;
  31.  
  32.         std::cin >> user_input;
  33.  
  34.         if (user_input == 1)
  35.             ++num_answer1;
  36.         if (user_input == 2)
  37.             ++num_answer2;
  38.         if (user_input == 3)
  39.             ++num_answer3;
  40.     }
  41.  
  42.     // done polling, display results
  43.     std::cout << "1: ";
  44.     for (int i = 0; i < num_answer1; i++)
  45.         std::cout << " * ";
  46.     std::cout << std::endl;
  47.  
  48.     std::cout << "2: ";
  49.     for (int i = 0; i < num_answer2; i++)
  50.         std::cout << " * ";
  51.     std::cout << std::endl;
  52.  
  53.     std::cout << "3: ";
  54.     for (int i = 0; i < num_answer3; i++)
  55.         std::cout << " * ";
  56.     std::cout << std::endl;
  57.  
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement