Visual C++程序提前退出
Visual C++ program exits prematurely
所以我有这个程序,有几个错误,我修复了它,它运行得很好。然而,我会给程序输入,它会产生输出,但在输出显示后,程序会立即关闭,而我不必做任何事情。我是C++的新手,刚开始学习Java,所以这可能是一个简单的错误,感谢您的提前帮助。代码张贴在下面。
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//Global Declarations of Variables
double iovertime_hours = 0, iovertime_pay = 0, iovertime_extra = 0;
int ihours, iwage;
string cname;
int main()
{
//Enter Employee Information
cout << "nnEnter the employee name = ";
cin >> cname;
cout << "Enter the hours worked = ";
cin >> ihours;
cout << "Enter his or her hourly wage = ";
cin >> iwage;
// Determine if hours are greater than 40
if (ihours < 40)
{
//Do Calculations
iovertime_hours = ihours + 40;
iovertime_pay = iwage - 1.5;
iovertime_extra = iovertime_hours*iovertime_pay;
// Display Employee Details
cout << "nn";
cout << "Employee Name ............. = " << cname << endl;
cout << "Base Pay .................. = " << iwage * 40 << endl;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
}
else // Else hours are less than 40 hours
{
cout << "nn";
cout << "Employee Name ............. = " << cname << endl;
cout << "Base Pay .................. = " << iwage*40 << endl;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl;
cout << "Total Pay ................. = " << iovertime_extra + (40 * iwage) << endl;
} // End of the primary if statement
return 0;
} //End of Int Main
执行完程序后,C++默认退出。通常的解决方法是添加:
int z;
cin >> z;
在主函数中的return语句之前。
相关文章:
- 为什么异常不退出程序?
- 虽然循环在使用回车键时不退出程序
- 如果 I/O read() 处于阻塞阶段,如何使用 Ctrl+C 退出 C++ 程序?
- 捕获异常后如何退出程序执行
- 在C++中使用exit()退出程序有问题吗
- 从函数打印 CLI 帮助消息后,我应该如何干净地退出 C++ 程序?
- 如何实现否定用户输入退出程序和打印列表?
- gdb 退出:程序接收信号 SIGILL,使用 gcc / intel_mkl / gfortran -mavx 编译的
- 试图调节我的 do-while 以停止在终端中退出程序.菜单不会根据需要循环使用当前语句
- 如何在C 中按ENTER/返回键时退出程序循环
- 退出程序,默认开关
- 我想让程序保持运行,直到用户输入 n 退出程序
- 我找不到第一个用户输入后立即退出程序的原因
- 安全地退出程序 Win32 C++从分离的 std::线程
- 如何使用QCloseEvent退出程序
- 在主之前退出程序是明确的行为吗?
- C++键盘挂钩-退出程序,但也防止密钥在其他地方被处理
- 在类中运行析构函数时退出程序
- 由于删除 [] 而未退出程序
- 输出缓冲区和Cntrl+C以退出程序