본문 바로가기
문제풀이/명품 C++ Programming

[명품 C++ Programming] 2장 Open Challenge

by 민됴리 2020. 12. 10.
반응형

2018년에 3월 5일에 발행된

황기태 저자의

명품 C++ Programming 개정판

2장 Open Challenge 문제입니다.

 

저작권을 준수하기 위해서

책에 나와있는 문제는 적지 않고

정답만 적었습니다.

 

궁금한 점은 댓글로 남겨주세요.

 


 

 

#include <iostream>
#include <string>
using namespace std;

int main(void) {

	string player1;
	string player2;
	int win; //1: player1 승리, 2: player2 승리, 3: 비김

	cout << "가위 바위 보 게임을 합니다. 가위, 바위, 보 중에서 입력하세요." << endl;
	cout << "로미오>>";
	cin >> player1;
	cout << "줄리엣>>";
	cin >> player2;

	if (player1 == "가위") {
		if (player2 == "가위") win = 3;
		else if (player2 == "바위") win = 2;
		else if (player2 == "보") win = 1;
	}
	else if (player1 == "바위") {
		if (player2 == "가위") win = 1;
		else if (player2 == "바위") win = 3;
		else if (player2 == "보") win = 2;
	}
	else if (player1 == "보") {
		if (player2 == "가위") win = 2;
		else if (player2 == "바위") win = 1;
		else if (player2 == "보") win = 3;
	}

	if (win == 1) {
		cout << "로미오가 이겼습니다." << endl;
	}
	else if (win == 2) {
		cout << "줄리엣이 이겼습니다." << endl;
	}
	else if (win == 3) {
		cout << "비겼습니다." << endl;
	}

	return 0;
}

 

반응형