C++의 첫 번째 프로그램에 문제가 있습니다.이 계산기를 썼지 만 어떤 이유로 작동 문자를 입력하면 어떤 이유로 든 오류가 표시되지 않습니다. 그냥 종료됩니다. 이 (당신이 창에서 코딩하는 경우) 당신은 단지 반환하기 전에 마지막C++ 계산기 종료
system("pause");
를 삽입하는 오순절을 고칠 수
#include <iostream>
using namespace std;
int main()
{
float n1;
float n2;
float n3;
int op;
cout << "Welcome to my calculator" << endl;
cout << "Type the first number: ";
cin >> n1;
cout << "Type the second number: ";
cin >> n2;
cout << "Type the number for the operation" << endl;
cout << "1 = addition" << endl;
cout << "2 = subvision" << endl;
cout << "3 = multiply" << endl;
cout << "4 = division" << endl;
cin >> op;
if(op == 1)
{
n3 = n1 + n2;
cout << "The result is " << n3 << endl;
}
if(op == 2)
{
n3 = n1 - n2;
cout << "The result is " << n3 << endl;
}
if(op == 3)
{
n3 = n1 * n2;
cout << "The result is " << n3 << endl;
}
if(op == 4)
{
n3 = n1/n2;
cout << "The result is " << n3 << endl;
}
return 0;
}
잘 작동합니다. 콘솔 (cmd.exe)에서 실행하십시오. – jrok
아니면 그 결과를 출력하고, 그 다음엔 종료하지만 그 결과가 너무 가까이서 결과를 보지 못하게됩니까? 파일의 맨 아래에 여분의'cin >> something;을 추가하십시오. –
저의 작품 - 출력물이 VisualC의 출력 로그에 연결되어있는 것처럼 보입니다. 콘솔에서 실행하여 실제로 무엇을하는지 확인하십시오. – ccbunney