~cpp #include <iostream> #include <ctime> using namespace std; int main() { int num1, num2, num3; int strike = 0; int ball = 0; int out = 0; cout << "=숫자 야구 하기=\n" do { srand(time(0)); num1 = (rand() % 9) + 1; num2 = (rand() % 9) + 1; num3 = (rand() % 9) + 1; cout << "발생한 숫자 : " << num1 << num2 << num3 << "\n"; }while((num1==num2)|| (num2==num3) || (num3==num1)); int value; do{ cout << "숫자 입력 : "; cin >> value; int value1 , value2, value3; value1 = value /100; value2 = (value%100) / 10; value3 = (value%100) %10; strike=0; ball=0; out=0; if (value1 == num1 ) strike++; else if (value1 == num2 || value1 == num3) ball++; else out++; if (value2 == num2 ) strike++; else if (value2 == num1 || value2 == num3) ball++; else out++; if (value3 == num3 ) strike++; else if (value3 == num1 || value3 == num2) ball++; else out++; cout << "결과 : " << strike<<"s " << ball << "b " << out << "o " << "\n\n"; if (strike != 3) cout << "틀렸습니다. 다시 입력\n"; }while (strike != 3); cout << "정답입니다!!\n"; return 0; }