繁体   English   中英

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

[英]Why does my program not work as an exe file?

嗨,我是这个编程技术的新手。 我刚刚开始学习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;

}

输入第二个数字后,程序将执行其操作并打印结果。 然后完成,因此退出并关闭其窗口。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM