当我运行程序时,它setprecision
适用于所有变量。我试图让变量secondsinput
成为一个整数。我已经尝试将该变量设置为 int ,但这会搞砸数学。有任何想法吗 ?
using namespace std;
int main()
{
double outputminutes, outputhours, outputdays, secondsinput;
cout << "Please enter the number of seconds: ";
cin >> secondsinput;
cout << endl;
outputminutes = secondsinput / 60;
outputhours = secondsinput / 3600;
outputdays = secondsinput / 86400;
cout << setprecision(2) << fixed;
if (secondsinput > 60 && secondsinput < 3600)
cout << secondsinput << " seconds is "
<< outputminutes << " minutes."
<< endl << endl;
else if (secondsinput > 3600 && secondsinput < 86400)
cout << secondsinput << " seconds is "
<< outputhours << " hours."
<< endl << endl;
else if (secondsinput > 86400)
cout << secondsinput << " seconds is "
<< outputdays << " days."
<< endl << endl;
}