No older revisions available
No older revisions available
~cpp
#include <iostream>
#include <ctime>
using namespace std;
void strike_ball();
int random_input[3];
int input[3];
int strike,ball;
int main()
{
int question;
cout << "야구 게임입니다." << endl;
srand((time(0)));
do
{
random_input[0] = rand()%10;
random_input[1] = rand()%10;
random_input[2] = rand()%10;
} while(random_input[0] == random_input[1] || random_input[1] == random_input[2] || random_input[0] == random_input[2]);
cout << "\t" << random_input[0] << random_input[1] << random_input[2] << endl;
for (int i = 1 ; i<= 8 ; i++)
{
cout << i << " 번째 -> ";
cin >> question;
input[2] = question%10;
input[1] = (question%100 - input[2])/10;
input[0] = (question - input[1]*10 - input[2])/100;
if (input[0] == input[1] || input[1] == input[2] || input[0] == input[2])
{
cout << "다시 입력하십시오." << endl;
i--;
}
else
{
strike_ball();
cout << strike << " strike, " << ball << "ball 입니다." << endl;
}
if (strike == 3)
{
cout << "축하합니다. 맞추셨습니다." << endl;
return 0;
}
}
cout << "게임 오버입니다." << endl;
return 0;
}
void strike_ball()
{
strike = 0;
ball = 0;
for (int i = 0 ; i <= 2 ; i++)
{
if (input[i] == random_input[i])
strike++;
}
if (input[0] == input[1])
ball++;
if (input[1] == input[2])
ball++;
if (input[0] == input[2])
ball++;
}