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

Why does my program not work as an exe file?

本文关键字:exe 文件 工作 我的 程序 不能 为什么      更新时间:2023-10-16

大家好,我是编程新手。我刚刚开始学习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 Numbern";
       cin>>a;
       cout << "Enter Your Second Numbern";
       cin>>b;
       int sum = a+b;
       cout << "Here is the sum of the two numbers:" <<sum;
   }
   else if(input == "Subtraction"){
        cout << "Enter Your First Numbern";
        cin>>a;
        cout << "Enter Your Second Numbern";
        cin>>b;
        int sub = a-b;
        cout<< "Here is the subtraction of the two numbers:" << sub;
   }
   else if(input == "Multiplication")
   {
        cout << "Enter Your First Numbern";
        cin>>a;
        cout << "Enter Your Second Numbern";
        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;
}

输入第二个数字后,程序将执行其任务并打印结果。然后它就完成了,所以它退出并且它的窗口关闭。

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