为什么我的程序不能用作exe文件?

时间:2015-08-05 22:52:08

标签: c++ exe

嗨,我是这个编程的新手。我刚刚开始学习C ++,为大学二年级做准备。 所以我正在学习一些教程并得到这个"计算器"计划完成。我使用CodeBlocks作为我的IDE。它会自动创建一个exe文件,您可以打开并运行该程序。在我运行的IDE中。一切都按预期完美运作。

然而,运行exe程序后,我会在输入第二个数字后自动关闭。它不是显示两个数字的总和差异或乘积,而是关闭它。

这是我的代码

#include <iostream>

using namespace std;

int main()
{
string input;

   cout << "Addition(A), Subtraction(S), Multiplication(M), or Division(D)"<<endl;
   cin >>input;
   int a;
   int b;

   if(input == "Addition")
   {
       cout << "Enter Your First Number\n";
       cin>>a;
       cout << "Enter Your Second Number\n";
       cin>>b;
       int sum = a+b;
       cout << "Here is the sum of the two numbers:" <<sum;
   }
   else if(input == "Subtraction"){
        cout << "Enter Your First Number\n";
        cin>>a;
        cout << "Enter Your Second Number\n";
        cin>>b;
        int sub = a-b;
        cout<< "Here is the subtraction of the two numbers:" << sub;
   }
   else if(input == "Multiplication")
   {
        cout << "Enter Your First Number\n";
        cin>>a;
        cout << "Enter Your Second Number\n";
        cin>>b;
        int product = a*b;
        cout<< "Here is the product of the two numbers:" << product;
   }
   else if(input == "Division")
   {
       cout<<"No Division Please.";
   }
return 0;

}

1 个答案:

答案 0 :(得分:2)

在给出第二个数字后,程序将执行其操作并打印结果。然后它就完成了,所以它退出并关闭它的窗口。

在现有的控制台窗口中启动它,以便在程序终止后查看该程序的输出。

相关问题