U E D R , A S I H C RSS

NumberBaseballGame/영록 (rev. 1.1)

Number Baseball Game/영록

// 숫자 야구 게임입니다.
#include <iostream>
#include <stdlib.h>
#include <ctime>
using namespace std;
int main()
{
	unsigned int number1,number2,number3;
	srand(time(0));
    unsigned int a,b,c;
	
	do
	{
		a = rand()%9+1; 
		b = rand()%9+1;
		c = rand()%9+1;
	}
	while ( a==b || b==c ||a==c);
	
	
    cout<<a<<" "<<b<<" "<<c<<endl;
    
	
	cout << "숫자야구 게임입니다.\n";
	while(1)
	{
		int count1=0,count2=0,count3=0;
		cout<<"숫자를 입력하십시오.{ ex) 3 4 5 } : ";
		char input[3];
		cin.get(input[0]);
        cin.get(input[1]);
		cin.get(input[2]);
		cin.get();

		number1 = input[0]-48;
		number2 = input[1]-48;
		number3 = input[2]-48;
		
		if(a == number1)  
			count1++;
		else if(a == number2 || a == number3 )
			count2++;
		if(b == number1 || b == number3)  
			count2++;
		else if(b == number2)
			count1++;
		if(c == number1 || c == number2)
			count2++;
		else if( c == number3) 
			count1++;		
		count3 = 3- count1- count2;
		cout <<"스트라이크" <<" "<<count1<<" "<<"볼"<<" "<<count2<< " " <<"아웃"<<" "<<count3<<"\n";	
		
		if(count1 == 3)
			break;
		}
    	return 0;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:52
Processing time 0.0212 sec