2012-09-21 4 views
0

나는 학습을위한 연습으로 간단한 계산기를 만들었고 나는 비틀어졌다 - 첫 번째 숫자에 대한 사용자 입력을 얻었지만 두 번째 입력에 대한 int를 저장하지 못함 - 개체를 만들어야합니까? ? 이것은 명백한 문제라고 생각합니다 ...C++의 간단한 계산기

//Simple calculator to work out the sum of two numbers (using addition) 

#include <cstdlib> 
#include <iostream> 

using namespace std; 

int main(int argc, char *argv[]) 
{ 
    cout << "Enter the first int: \n"; 
    int input1 = std::cin.get(); 

    cout << "Enter the second int: \n"; 
    int input2 = std::cin.get(); 


    cout << "The sum of these numbers is: " << input1 + input2; 
    cout << "\n"; 


    system("PAUSE"); 
    return EXIT_SUCCESS; 
} 
+0

입력 번호는 어떻게 입력합니까? – Riskhan

답변

9

cin.get()은 입력의 한 문자 만 검색합니다. 왜 또한 사용자가 입력 한 모든 잉여 줄 바꿈 또는 공백 문자를 돌봐 (operator>>와) std::cin이 방법을 사용하여

int input1, input2; 
cout << "Enter the first int: \n"; 
cin >> input1; 
cout << "Enter the second int: \n"; 
cin >> input2; 

를 사용하지 마십시오.