2강 과제 ( 함수사용 가위바위보)

#include <iostream> // 콘솔 입출력
#include <stdlib.h> // 랜덤 모듈
#include <time.h> // 타임 추출
#include <string>

using namespace std;



void Turn(string name, int turn){
cout << name;
cout << "가";
if (turn == 1) cout << "[ 가위 ]";
else if (turn == 2) cout << "[ 바위 ] ";
else cout << "[ 보 ]";
cout << " 를 냈습니다" << endl;
}

void kBBGame(int player, int comp){

if ((player == 1 && comp == 1) || (player == 2 && comp == 2) || (player == 3 && comp == 3)){
cout << " 비겼습니다. " << endl;
}
else if ((player == 1 && comp == 3) || (player == 2 && comp == 1) || (player == 3 && comp == 2)){
cout << " 플레이어가 이겼습니다. " << endl; }
else{
cout << " 플레이어가 졌습니다. " << endl; }
}


void main(){
int playerKBB;
int computerKBB;

//시드섞기
srand((unsigned int)time(NULL));
computerKBB = rand() % 3 + 1;

cout << "플레이어(1:가위,2:바위,3:보) >>>";
cin >> playerKBB; 

Turn(" 플레이어", playerKBB);
Turn(" 컴퓨터가", computerKBB);
kBBGame(playerKBB, computerKBB);
}

댓글

이 블로그의 인기 게시물

날짜 시간 시간차 시간 계산 하기

코루틴에서 CallBack 함수 적용하기

C++ 언어 퍼센트 구하는 방법 / 기본 언어 퍼센트 구하는 방법