1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
//5 tickets. Either randomly select 6 numbers (1-60) for each ticket or 6 values.
//Compare all their tickets to the winning lotto numbers.
//For each ticket show numbers and how many matches.
//Issues: Running into duplicate numbers on tickets. Error check for dupes on each ticket.
// Error check on num_errorcheck is not working properly
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>
using namespace std;
int menu_errorcheck(int users_choice)
{
//Error check the entered users numbers to see if they are either 1 or 2
while (users_choice > 2 || users_choice < 1)
{
cout << endl << endl;
cout << "Invalid option" << endl;
cout << "Please enter choice again: ";
cin >> users_choice;
}
return users_choice;
}
void num_errorcheck(int lotto[], int array_size)
{
//this is supposed to error check the entered users numbers to see if they are within 1-60. *This is not working.
//It is not checking for dupes and allowing numbers out of range. Other anomalies. ???
while (lotto[0] > 60 || lotto[0] < 1 || lotto[1] > 60 || lotto[1] < 1 || lotto[2] > 60 || lotto[2] < 1
|| lotto[3] > 60 || lotto[3] < 1 || lotto[4] > 60 || lotto[4] < 1 || lotto[5] > 60 || lotto[5] < 1)
{
for (int i = 0; i < array_size; i++)
{
cout << "Invalid number entry, try again.";
cout << "Please enter " << array_size << " values: ";
cin >> lotto[i];
}
cout << endl << endl;
break;
}
}
void populate_ticket(int lotto[], int array_size)
{
//Populate tickets manually or automatically when called upon
cout << "\t***** Menu *****" << endl;
cout << "1. Choose lotto numbers for ticket" << endl;
cout << "2. Randomize lotto numbers for ticket" << endl;
cout << "Enter choice: ";
int users_choice;
cin >> users_choice;
users_choice = menu_errorcheck(users_choice);
cout << endl << endl;
switch (users_choice)
{
case 1:
//function allows the user to enter 6 (unique?) lotto ticket numbers
cout << "Please enter " << array_size << " values: ";
for (int i = 0; i < array_size; i++)
{
cin >> lotto[i];
}
cout << endl << endl;
break;
case 2:
//Randomly gen 6 (unique?) lotto ticket numbers
cout << "Randomizing lotto ticket numbers" << endl;
srand(time(0));
for (int i = 0; i < array_size; i++)
{
lotto[i] = rand() % 60;
}
cout << endl << endl;
break;
}
}
int main()
{
//Declare variables
int users_choice;
const int array_size = 6;
int ticket_1[array_size];
int ticket_2[array_size];
int ticket_3[array_size];
int ticket_4[array_size];
int ticket_5[array_size];
//Menu: Select random number gen or pick numbers. (do-while?)
cout << "Starting with 5 tickets that each contain 6 numbers between 1 - 60." << endl;
cout << "Choose the 6 numbers manually or have the numbers randomized." << endl;
cout << endl;
cout << "\t\t Press [Enter] to begin.";
cin.ignore();
cout << endl << endl;
//Switch board of either (1) picked numbers or (2) random numbers being given to them and sends info to array
populate_ticket(ticket_1, array_size);
num_errorcheck(ticket_1, array_size);
cout << endl << endl;
cout << "\t\t Press [Enter] to choose ticket 2.";
cout << endl << endl;
populate_ticket(ticket_2, array_size);
num_errorcheck(ticket_2, array_size);
cout << endl << endl;
cout << "\t\t Press [Enter] to choose ticket 3.";
cout << endl << endl;
populate_ticket(ticket_3, array_size);
num_errorcheck(ticket_3, array_size);
cout << endl << endl;
cout << "\t\t Press [Enter] to choose ticket 4.";
cout << endl << endl;
populate_ticket(ticket_4, array_size);
num_errorcheck(ticket_4, array_size);
cout << endl << endl;
cout << "\t\t Press [Enter] to choose ticket 5.";
cout << endl << endl;
populate_ticket(ticket_5, array_size);
num_errorcheck(ticket_5, array_size);
cout << "Your ticket numbers are: " << endl;
cout << "Ticket 1: ";
for (int i = 0; i < array_size; i++)
{
cout << ticket_1[i] << " ";
}
cout << endl;
cout << "Ticket 2: ";
for (int i = 0; i < array_size; i++)
{
cout << ticket_2[i] << " ";
}
cout << endl;
cout << "Ticket 3: ";
for (int i = 0; i < array_size; i++)
{
cout << ticket_3[i] << " ";
}
cout << endl;
cout << "Ticket 4: ";
for (int i = 0; i < array_size; i++)
{
cout << ticket_4[i] << " ";
}
cout << endl;
cout << "Ticket 5: ";
for (int i = 0; i < array_size; i++)
{
cout << ticket_5[i] << " ";
}
//Array containing stored user lotto numbers as well as the actual lotto numbers is accessed to
//check how many matches there are (if...then...else,)
//The system displays how correct each ticket is (if...then...else)
cout << endl << endl;
system("pause");
return 0;
}
|