2014-12-13 2 views
-2

이 게임에서는 플레이어가 이름을 쓰길 원합니다. 그러나 컴퓨터가 단지 이름을 받아들입니다. 어떻게해야합니까?C++ 2 cinch.getline after echader

입력 : 게임 밥에 에 오신 것을 환영하고, 이제 컴퓨터 둘 중 하나 선택 : 밥 는

출력 결혼. 선택된 하나가 게임을 잘

#include<cstring> 
     #include<iostream> 
     using namespace std; 
     int main(){ 
     int choose; 
     cin>>choose; 
     if(choose==1){ 
      char name1[30],name2[30]; 
      cout<<"Hi player 1\nWhat's your name?\n"; 
      cin.getline(name1,30); 
      cout<<"Hi player 2\nWhat's your name?\n"; 
      cin.getline(name2,30); 
      cout<<"Welcome to the game"<<name1<<"and"<<name2<<"Now the Computer chooses one of you.The chosen one will start the game\n\n"; 
} 
+0

내 대답을 확인하고 알려주세요. –

+0

다시 확인해 주시겠습니까? cin 부분을 잊어 버렸습니다. –

답변

1

를 시작, 내가 조금 코드를 변경하고 그것을 잘 작동합니다.

#include <string> 
#include<iostream> 
#include <conio.h> 
using namespace std; 
int main(){ 
    int choose; 
    cin >> choose; 
    if(choose == 1){ 
     string name1, name2; 
     cout << "Hi player 1\nWhat's your name?\n"; 
     cin >> name1; 
     cout << "Hi player 2\nWhat's your name?\n"; 
     cin >> name2; 
     cout << "Welcome to the game" << name1 << "and" << name2 << "Now the Computer chooses one of you.The chosen one will start the game\n\n"; 
    } 
    _getch(); 
    return 0; 
} 

그리고 이름 길이에 제한이 없습니다.

+0

고마워. 너는 나를 너무 많이 도와 줬어! 굉장해! –