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
|
/*
/*
* Standard Library Include Files
*/
#include <iostream> // Needed for typing/printing in Console
#include <Windows.h> // Not sure if C version... Where to get C++ version?
#include <fstream> // Need to create, open, close files (File System)
#include <string> //
/*
* Prototypes // This lets me place any function wherever i want in the code
*/
bool inputNumbers();
void mainMenu();
void findRecurringNumber();
/*
* Driver Program (Main Function) Every program needs one
*/
void main()
{
mainMenu();
}
/*
* Functions Start Here
*/
// This particular function is used to clear the cache of the Output/Input executable screen
void clearScreen()
{
std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
system("CLS"); // Clears screen input and retries login attempt
std::cout << std::flush;
std::cin.clear();
fflush(stdin);
}
// This function gives a menu (which you can choose) of what you want to do
void mainMenu()
{
clearScreen();
std::cout << "What would you like to do?\n"
<< "Press (0), to exit\n"
<< "Press (1), to open the numbers document\n"
<< "Press (2), to input 6 more numbers into the document\n"
<< "Press (3) to find the most recurring numbers in the document\n"
<< "Your answer: ";
// Create variable for user input
int l_userInput;
std::cin >> l_userInput;
// Switch case to the case that is needed.
switch (l_userInput)
{
case 0:
{
std::cout << "Goodbye!\n";
exit(0);
}
case 2:
{
std::cout << "You have chosen to input 6 more numbers into the file\n";
Sleep(2500);
inputNumbers();
break;
}
case 3:
{
std::cout << "Find Reccuring Number\n";
Sleep(2500);
findRecurringNumber();
}
}
}
// Input 6 numbers into the document (HOW DO I MAKE IT BETWEEN 1-6), and numbers above 9+ e.g. 32
bool inputNumbers()
{
clearScreen(); // Clears screen input and retries login attempt
std::cout << "Please input the last 6 numbers from the Conquer Lotto game: ";
// Variables to input the first 6 digits in the exe cache
int a, b, c, d, e, f;
std::cin >> a;
std::cin >> b;
std::cin >> c;
std::cin >> d;
std::cin >> e;
std::cin >> f;
std::cout << a << ", " << b << ", " << c << ", " << d << ", " << e << ", " << f << "\n";
std::cout << std::endl;
std::cin.clear();
// If this looks correct... Contiue
char input;
std::cout << "If this looks correct please type (y), if not type (n): ";
std::cin >> input;
if (input == 'y')
{
//inputToFile(a, b, c, d, e, f);
return true;
}
else
{
inputNumbers();
return false;
}
}
// Find recurring numbers function
// How do i shorten this program to make it more readable?
// How do i implement more numbers... E.g. up to 36.
// How do i only print the most reccurred number?
void findRecurringNumber()
{
clearScreen(); // Clears screen input and retries login attempt
int x = 0;
std::cout << "-----------------------------------" << "\n";
std::cout << "|---> MOST COMMON NUMBERS ARE <---|" << "\n";
std::cout << "-----------------------------------" << "\n\n";
int max_countOf1{ 0 }; // This number will increase as getLine(IN File) finds number 1;
std::string a{ '1' }; // References to find number 1 in file.
int max_countOf2{ 0 }; // This number will increase as getLine(IN File) finds number 2;
std::string b{ '2' }; // References to find number 2 in file.
int max_countOf3{ 0 }; // This number will increase as getLine(IN File) finds number 3;
std::string c{ '3' }; // References to find number 3 in file.
int max_countOf4{ 0 }; // This number will increase as getLine(IN File) finds number 4;
std::string d{ '4' }; // References to find number 4 in file.
int max_countOf5{ 0 }; // This number will increase as getLine(IN File) finds number 5;
std::string e{ '5' }; // References to find number 5 in file.
int max_countOf6{ 0 }; // This number will increase as getLine(IN File) finds number 6;
std::string f{ '6' }; // References to find number 6 in file.
int max_countOf7{ 0 }; // This number will increase as getLine(IN File) finds number 7;
std::string g{ '7' }; // References to find number 7 in file.
int max_countOf8{ 0 }; // This number will increase as getLine(IN File) finds number 8;
std::string h{ '8' }; // References to find number 8 in file.
int max_countOf9{ 0 }; // This number will increase as getLine(IN File) finds number 9;
std::string i{ '9' }; // References to find number 9 in file.
// Handle negative numbers
if (x < 0)
{
x = -x;
}
// Initial Setup
std::string line;
std::ifstream numbersFile;
numbersFile.open("numbers.nbr");
if (numbersFile.is_open())
{
while (getline(numbersFile, line))
{
if (line == a) // Refer above... If Number 1 is found... ++ to max_countOf1
{
max_countOf1++;
}
else if (line == b) // Refer above... If Number 2 is found... ++ to max_countOf1
{
max_countOf2++;
}
else if (line == c) // Refer above... If Number 3 is found... ++ to max_countOf1
{
max_countOf3++;
}
else if (line == d) // Refer above... If Number 4 is found... ++ to max_countOf1
{
max_countOf4++;
}
else if (line == e) // Refer above... If Number 5 is found... ++ to max_countOf1
{
max_countOf5++;
}
else if (line == f) // Refer above... If Number 6 is found... ++ to max_countOf1
{
max_countOf6++;
}
else if (line == g) // Refer above... If Number 7 is found... ++ to max_countOf1
{
max_countOf7++;
}
else if (line == h) // Refer above... If Number 8 is found... ++ to max_countOf1
{
max_countOf8++;
}
else if (line == i) // Refer above... If Number 9 is found... ++ to max_countOf1
{
max_countOf9++;
}
}
// These lines Print the numbers 1-9 (How many were found in the file)
std::cout << "Number of '1's recorded: " << max_countOf1 << "\n";
std::cout << "Number of '2's recorded: " << max_countOf2 << "\n";
std::cout << "Number of '3's recorded: " << max_countOf3 << "\n";
std::cout << "Number of '4's recorded: " << max_countOf4 << "\n";
std::cout << "Number of '5's recorded: " << max_countOf5 << "\n";
std::cout << "Number of '6's recorded: " << max_countOf6 << "\n";
std::cout << "Number of '7's recorded: " << max_countOf7 << "\n";
std::cout << "Number of '8's recorded: " << max_countOf8 << "\n";
std::cout << "Number of '9's recorded: " << max_countOf9 << "\n";
}
}
|