CPP - Array_For_LottoGenerator
#include <iostream>
#include <time.h>
#include <iomanip>
using namespace std;
#define LOTTO 45
typedef enum
{
FORTH = 3,
THIRD,
SECOND,
FIRST
}GRADE;
static const char *grade[] = {NULL,NULL,NULL,
"ForthGrade", "ThirdGrade", "SecondGrade", "FirstGrade"
};
int main() {
srand((unsigned int)time(0));
int iLotto[LOTTO] = {};
int iuInput, iaInput;
int iuSort[6]={},iaSort[6] = {};
cout << "Please select number of Lotto between 1 to 6 :";
cin >> iuInput;
iuInput *= 6;
iaInput = rand()%6 +1;
iaInput *= 6;
// Create a number of Lotto
for (int i = 0; i < LOTTO; ++i)
{
iLotto[i] = i +1;
}
// Shuffle
int iTemp, iIdx1, iIdx2;
for(int i = 0; i < LOTTO *4; ++i)
{
iIdx1 = rand() % LOTTO;
iIdx2 = rand() % LOTTO;
iTemp = iLotto[iIdx1];
iLotto[iIdx1] = iLotto[iIdx2];
iLotto[iIdx2] = iTemp;
}
cout << endl;
// Print a number of Lotto
cout << "\n***L*****O******T******T******O***\n";
for (int i = 0; i < LOTTO; ++i)
{
cout << setw(5) << iLotto[i];
if(i % 6 == 5)
cout << endl;
}
cout << "\n***L*****O******T******T******O***\n";
cout << endl;
// Asignment user lotto number
for (int i = 0; i < 6; ++i)
{
iuSort[i] = iLotto[iuInput +i];
}
// Sort user lotto number
for (int i = 1; i < 6; ++i)
{
for(int j = 0; j < i + 1; ++j)
{
if (iuSort[j] > iuSort[i])
{
int iTemp = iuSort[j];
iuSort[j] = iuSort[i];
iuSort[i] = iTemp;
}
}
}
// Asignment AI lotto number
for (int i = 0; i < 6; ++i)
{
iaSort[i] = iLotto[iaInput +i];
}
// Sort AI lotto number
for (int i = 1; i < 6; ++i)
{
for(int j = 0; j < i + 1; ++j)
{
if (iaSort[j] > iaSort[i])
{
int iTemp = iaSort[j];
iaSort[j] = iaSort[i];
iaSort[i] = iTemp;
}
}
}
// Print user lotto number
cout << "User's Lotto number is ";
for (int i = 0; i < 6; ++i)
{
cout <<setw(5) << iuSort[i];
}
cout << endl;
// Print AI lotto number
cout << "Winning Lotto number is ";
for (int i = 0; i < 6; ++i)
{
cout <<setw(5) << iaSort[i];
}
cout << endl;
// Conform winning number
int iConform = 0, i = 0;
while(i < 6)
{
++i;
if (iuSort[iConform] == iaSort[iConform])
++iConform;
}
cout << endl << iConform << endl;
// Grade
switch(iConform)
{
case FORTH:
cout << "\n " << grade[FORTH] << endl;
break;
case THIRD:
cout << "\n " << grade[THIRD] << endl;
break;
case SECOND:
cout << "\n " << grade[SECOND] << endl;
break;
case FIRST:
cout << "\n " << grade[FIRST] << endl;
cout << "Congratulation !!!";
break;
default:
cout << "I am sorry but, next time\n";
break;
}
return 0;
}
'my_lesson > _C++' 카테고리의 다른 글
C++ - Array_For_LottoGame Ver 1.2 functional (0) | 2019.04.10 |
---|---|
C++ - Array_For_BaseballGame Ver.1.0 (0) | 2019.04.05 |
CPP - Array _ For _ LottoGenerator 1.0 (0) | 2019.04.04 |
CPP - Repeat While, RackPaperScissors_Game (0) | 2019.04.03 |
CPP - Condition If , Switch (0) | 2019.04.03 |
댓글