Guest User

bad

a guest
Sep 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main()
  5. {
  6.     //Initialize vectors
  7.     std::vector<int> numbers; //Stores the inputted numbers in 1 sequence
  8.     std::vector<int> luckyNumbers; //Stores any lucky numbers if they are found
  9.  
  10.     std::vector<int> big;
  11.  
  12.     int winningAmount = 0;
  13.  
  14.     // To find lucky numbers
  15.     int luckynumber = 0;
  16.     constexpr int Not_found = -1;
  17.     int found = Not_found;
  18.     int counter = 0;
  19.  
  20.     constexpr int NOTFOUND = -1;
  21.     int FOUND = NOTFOUND;
  22.     int COUNTER = 0;
  23.  
  24.     int option = 1;
  25.     int all = 0;
  26.  
  27.     do {
  28.         //Display question
  29.         std::cout << "Enter your ticket numbers: ";
  30.  
  31.         //Read value
  32.         numbers.resize(10);
  33.         for (int x = 0; x < 10; x++)
  34.         {
  35.             std::cin >> numbers[x];
  36.         }
  37.  
  38.         // Display and read option
  39.         std::cout << "One more ticket? ";
  40.         std::cin >> option;
  41.  
  42.         luckynumber = 0; //Resets the lucky number value
  43.         luckynumber = numbers.front() + numbers.back(); // The lucky number is the sum of the first and last number in the ticket
  44.  
  45.         found = Not_found; //Necessary to always check a new value
  46.         // For loop used to find a lucky number
  47.         for (int e : numbers)
  48.         {
  49.             if (e == luckynumber) //If the lucky number is found
  50.             {
  51.                 found = counter;
  52.                 break; //Stop searching, break the loop
  53.             }
  54.             ++counter;
  55.         }
  56.  
  57.         // Add 2000 to the winning amount if a lucky number is found
  58.         if (found != Not_found)
  59.         {
  60.             winningAmount += 2000;
  61.             luckyNumbers.push_back(luckynumber); //Save the lucky number in a vector
  62.         }
  63.  
  64.     } while (option == 1); //Loops if the option chosen is 1
  65.  
  66.     // Display sequence of lucky numbers if they are found
  67.     if (luckyNumbers.size() != 0) //If the vector size isn't 0, that means lucky numbers have been found
  68.     {
  69.         std::cout << "Your lucky numbers: ";
  70.         for (int i : luckyNumbers)
  71.         {
  72.             std::cout << i << " ";
  73.         }
  74.  
  75.     }
  76.  
  77.     // Display winning amount
  78.     std::cout << "\n" << "Your winning amount is: " << winningAmount << "\n";
  79.  
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment