在打印输出之前输入后程序退出

时间:2017-08-27 22:55:46

标签: c++ windows debugging

我编写了以下程序,但打印不正确。输入速率和小时后,控制台似乎只是关闭。

#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
    double hours, rate, pay;
    // Get the number of hours worked.
    cout << "How many hours did you work? ";
    cin >> hours;
    // Get the hourly pay rate.
    cout << "How much do you get paid per hour? ";
    cin >> rate;
    // Calculate the pay.
    pay = hours * rate;
    // Display the pay.
    cout << "You have earned $" << pay << endl;
    return 0;
}

1 个答案:

答案 0 :(得分:0)

程序打印结果并退出。这是正常的行为。您可以在return语句之前添加system("pause");以延迟关闭控制台。