Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- int main()
- {
- //Initialize vectors
- std::vector<int> numbers; //Stores the inputted numbers in 1 sequence
- std::vector<int> luckyNumbers; //Stores any lucky numbers if they are found
- std::vector<int> big;
- int winningAmount = 0;
- // To find lucky numbers
- int luckynumber = 0;
- constexpr int Not_found = -1;
- int found = Not_found;
- int counter = 0;
- constexpr int NOTFOUND = -1;
- int FOUND = NOTFOUND;
- int COUNTER = 0;
- int option = 1;
- int all = 0;
- do {
- //Display question
- std::cout << "Enter your ticket numbers: ";
- //Read value
- numbers.resize(10);
- for (int x = 0; x < 10; x++)
- {
- std::cin >> numbers[x];
- }
- // Display and read option
- std::cout << "One more ticket? ";
- std::cin >> option;
- luckynumber = 0; //Resets the lucky number value
- luckynumber = numbers.front() + numbers.back(); // The lucky number is the sum of the first and last number in the ticket
- found = Not_found; //Necessary to always check a new value
- // For loop used to find a lucky number
- for (int e : numbers)
- {
- if (e == luckynumber) //If the lucky number is found
- {
- found = counter;
- break; //Stop searching, break the loop
- }
- ++counter;
- }
- // Add 2000 to the winning amount if a lucky number is found
- if (found != Not_found)
- {
- winningAmount += 2000;
- luckyNumbers.push_back(luckynumber); //Save the lucky number in a vector
- }
- } while (option == 1); //Loops if the option chosen is 1
- // Display sequence of lucky numbers if they are found
- if (luckyNumbers.size() != 0) //If the vector size isn't 0, that means lucky numbers have been found
- {
- std::cout << "Your lucky numbers: ";
- for (int i : luckyNumbers)
- {
- std::cout << i << " ";
- }
- }
- // Display winning amount
- std::cout << "\n" << "Your winning amount is: " << winningAmount << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment