C++ での最初のプログラムで問題が発生しました。この計算機を作成しましたが、何らかの理由で演算文字を入力すると終了します。エラーなどは表示されず、ただ終了します。これは Visual C++ のコードです
#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;
}