숫자야구게임
~cpp #include <iostream> #include <ctime> using namespace std; void main() { srand(time(0)); int x1 = rand() % 10; int x2 = rand() % 10; while ( x2 == x1 ) x2 = rand() % 10; int x3 = rand() % 10; while ( x3 == x1 || x3 == x2) x3 = rand() % 10; cout << x1 << x2 << x3 << "\n"; cout << "숫자 세개를 입력하세요. : "; int a,b,c; cin >> a >> b >> c; int strike = 0; int ball = 0; while( !(x1 == a && x2 == b && x3 == c)) { if ( x1 == a ) strike++; if ( x2 == b ) strike++; if ( x3 == c ) strike++; if ( x1 == b || x1 == c) ball++; if ( x2 == a || x2 == c) ball++; if ( x3 == a || x3 == b) ball++; cout << strike << " strike, " << ball << "ball\n"; strike = 0; ball = 0; cout << "숫자 세개를 입력하세요. : "; cin >> a >> b >> c; } }