야구게임입니다!! 엄청 난잡합니다~~ 자세히 보지 마세요~!
~cpp
#include<iostream>
#include <ctime>
using namespace std;
int main()
{
int three;
int baek =0, il=0, sib=0;
int rbaek, ril, rsib;
int str = 0,ball = 0;
srand((time(0)));
ril = rand() % 10;
do
{
srand((time(0)));
rsib = rand() % 10;
}while(rsib == ril);
do
{
srand((time(0)));
rbaek = rand() % 10;
}while(rbaek == rsib);
cout <<"야구 게임 알지?? 시작!\n";
cout << "답 : " << rbaek << rsib << ril << endl;
while(rbaek != baek || rsib != sib || ril != il)
{
str = 0;
ball = 0;
cout <<"숫자 써봐~! 3자리.-> ";
while(!(cin >> three))
{
cin.clear();
while(cin.get() != '\n')
continue;
cout << "숫자를 쓰란말야~!";
}
if(three < 100 || three >999)
{
cout << "3자리랬지??--^ ";
while(!(cin >> three))
{
cin.clear();
while(cin.get() != '\n')
continue;
cout << "숫자를 쓰란말야~!";
}
baek = three / 100;
sib = (three % 100) / 10;
il = three % 10;
while(three < 100 || three > 999)
{
cout << "3자리랬지??--^ ";
while(!(cin >> three))
{
cin.clear();
while(cin.get() != '\n')
continue;
cout << "숫자를 쓰란말야~!";
}
baek = three / 100;
sib = (three % 100) / 10;
il = three % 10;
}
}
baek = three / 100;
sib = (three % 100) / 10;
il = three % 10;
if(baek == sib || baek == il || sib == il)
{
cout << "같은수는 입력하시 마쇼 ->";
while(!(cin >> three))
{
cin.clear();
while(cin.get() != '\n')
continue;
cout << "숫자를 쓰란말야~!";
}
baek = three / 100;
sib = (three % 100) / 10;
il = three % 10;
while(baek == sib || baek == il || sib == il)
{
cout << "같은수는 입력하시 마쇼 ->";
while(!(cin >> three))
{
cin.clear();
while(cin.get() != '\n')
continue;
cout << "숫자를 쓰란말야~!";
}
baek = three / 100;
sib = (three % 100) / 10;
il = three % 10;
}
}
if(baek == rbaek)
str++;
if(baek == ril || baek == rsib)
ball++;
if(sib == rsib)
str++;
if(sib == ril || sib == rbaek)
ball++;
if(il == ril)
str++;
if(il == rbaek || il == rsib)
ball++;
cout << "스트라이크 " << str << "개!\n";
cout << "볼 " << ball << "개!\n";
}
cout << "끝\n";
return 0;
}
NumberBaseballGame