카테고리 없음

[C++] up and down 게임

s뽈록이s 2013. 9. 23. 10:57
void main()
{
	int rand_su, su;
	rand_su = rand() % 101;

	while(rand_su != su)
	{
		cout << "0 ~ 100까지의 수를 입력해 주세요 : ";
		cin >> su;
		if(rand_su > su) cout << "up" << endl;
		else if(rand_su < su) cout << "down" << endl;
	}
	cout << "정답입니다.!" << endl;
}

프로그램 실행화면


생각보다 구현이 간단한 up and down 게임이다. while()의 조건식으로 사용자의 입력과 컴퓨터가 고른 랜덤의 값이 일치하지 않을 동안으로 해 놓고 입력한 값을 비교해 up과 down을 출력해 주면된다.