Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.22 KB | None | 0 0
  1. // Gameshow.cpp
  2. #include <iostream>
  3.  
  4.  
  5. int main() { // Begin main function.
  6.    
  7.     int answer;
  8.     int finalScore = 0;
  9.    
  10.     void promptAndWait();
  11.    
  12.     // Greet the user and explain the game.
  13.     std::cout << "Welcome to (Insert Gameshow Name Here)!'\n\n"
  14.     << "In this game, you will be asked 5 questions.\n"
  15.     << "You will be graded on your performance at the end.\n"
  16.     << "Your performance will be represented as a percentile.\n"
  17.     << "Each correct answer is worth 20% of the maximum percentage.\n"
  18.     << "The maximum percentage possible is 100%.\n\n"
  19.    
  20.     << "To answer, type the number next to the corresponding option.\n"
  21.     << "Do NOT type anything else.\n"
  22.     << "Press Enter twice to get started!\n\n";
  23.  
  24.     promptAndWait();
  25.    
  26.     // Question #1.
  27.     std::cout << "Question number one: What is the capital of Pennsylvania?\n\n"
  28.     << "1. Harrisburg\n"
  29.     << "2. Pittsburgh\n"
  30.     << "3. Montgomery\n"
  31.     << "4. Bismarck\n\n";
  32.    
  33.     std::cout<< "What is your answer?:";
  34.     std::cin >> answer;
  35.    
  36.     if (answer == 1) { // Answered Harrisburg.
  37.            std::cout << "Correct!\n\n";
  38.            
  39.            // Increase finalScore by 1.
  40.            finalScore++;
  41.            
  42.            std::cout << "Press Enter for the next question.\n\n\n\n\n\n";
  43.     } else { // Answered incorrectly.
  44.            std::cout << "I'm sorry.  The correct answer is 1. Harrisburg\n\n";
  45.            std::cout << "Press Enter twice for the next question.\n\n\n\n\n\n";
  46.            }
  47.    
  48.     promptAndWait();
  49.    
  50.     // Question #2.
  51.     std::cout << "Question number 2: What is 2+2\n\n"
  52.     << "1. Three\n"
  53.     << "2. Four\n"
  54.     << "3. Five\n"
  55.     << "4. Six\n\n";
  56.    
  57.         std::cout<< "Enter your answer?:";
  58.     std::cin >> answer;
  59.    
  60.     if (answer == 2) { // Answered Four.
  61.            std::cout << "Correct!\n\n";
  62.            
  63.            // Increase finalScore by 1.
  64.            finalScore++;
  65.            
  66.            std::cout << "Press Enter for the next question.\n\n\n\n\n\n";
  67.     } else { // Answered incorrectly.
  68.            std::cout << "I'm sorry.  The correct answer is 2. Four\n\n";
  69.            std::cout << "Press Enter for the next question.\n\n\n\n\n\n";
  70.            }
  71.            
  72.     promptAndWait();
  73.    
  74.     // Question #3.
  75.     std::cout << "Question number 3: What is the name of security expert Steve Gibson's\n"
  76.     << "hard drive maintenance program?\n\n"
  77.     << "1. SpinRite\n"
  78.     << "2. SpinRight\n"
  79.     << "3. TwirlRite\n"
  80.     << "4. TwirlRight\n\n"
  81.     << "Enter your answer: ";
  82.     std::cin >> answer;
  83.    
  84.     if (answer == 1) { // Answered SpinRite.
  85.                std::cout << "Correct!\n\n";
  86.                
  87.                // Increase finalScore by 1.
  88.                finalScore++;
  89.                
  90.                std::cout << "Press Enter for the next question.\n\n\n\n\n\n";
  91.     } else { // Answered incorrectly.
  92.                std::cout << "I'm sorry.  The correct answer is 1. SpinRite.\n\n"
  93.                << "Press Enter for the next question.\n\n\n\n\n\n";
  94.            }
  95.     promptAndWait();
  96.    
  97.     // Question #4.
  98.     std::cout << "Question number 4: What happens when Vince orders new computer parts?\n\n"
  99.     << "1. The parts work perfectly\n"
  100.     << "2. The parts fail catastrophically\n\n"
  101.     << "Enter your answer: ";
  102.     std::cin >> answer;
  103.    
  104.     if (answer == 2) { // Answered correctly.
  105.                std::cout << "Correct!\n\n";
  106.                
  107.                // Increase finalScore by 1.
  108.                finalScore++;
  109.                
  110.                std::cout << "Press Enter for the next question.\n\n\n\n\n\n";
  111.     } else { // Answered incorrectly.
  112.                std::cout << "I'm sorry.  The answer is 2. The parts fail catastrophically.\n\n"
  113.                << "Press Enter for the next question.\n\n\n\n\n\n";
  114.            }
  115.            
  116.     promptAndWait();
  117.    
  118.     // Final Question.
  119.     std::cout << "Final question: Whenever Caleb says anything, what happens?\n\n"
  120.     << "1. The statment becomes true.\n"
  121.     << "2. A person loses their job.\n"
  122.     << "3. Caleb gets a dollar.\n"
  123.     << "4. The statement becomes false.\n\n"
  124.     << "Enter your answer: ";
  125.    
  126.     std::cin >> answer;
  127.    
  128.     if (answer == 4) {
  129.                std::cout << "Correct!\n\n";
  130.                
  131.                // Increase finalScore by 1
  132.                finalScore++;
  133.                
  134.                std::cout << "Press Enter to see your results!\n\n\n\n\n\n\n";
  135.     } else {
  136.                std::cout << "I'm sorry.  The answer is 4.  The statment becomes false.\n\n"
  137.                << "Press Enter to see your results!\n\n";
  138.            }
  139.                
  140.     promptAndWait();
  141.    
  142.     // Calculate Percent.
  143.     int winPercent = (finalScore * 20);
  144.    
  145.     if (winPercent <=60) {
  146.                    std::cout << "Tough luck.  Your final score is " << winPercent << "% \n\n";
  147.     } else {
  148.                    std::cout << "Good job!  Your final score is " << winPercent << "% \n\n";
  149.            }
  150.    
  151.     system("PAUSE");
  152.     return EXIT_SUCCESS;
  153. } // End of main function
  154.  
  155.  
  156.  
  157.  
  158. // Define the promptAndWait() function
  159. void promptAndWait() {
  160.     std::cin.ignore(100, '\n');
  161.     std::cin.get();
  162. } // End of the promptAndWait() function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement