我编写了以下程序,但打印不正确。输入速率和小时后,控制台似乎只是关闭。
#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;
}
答案 0 :(得分:0)
程序打印结果并退出。这是正常的行为。您可以在return语句之前添加system("pause");
以延迟关闭控制台。