1
我有問題,使用模數試圖除以小數。我選擇了fmod來選擇3和4,但是當選擇了3和4時,選擇了英寸後程序將停止工作。我希望保持模數,因爲就像我們在課堂上所獲得的那樣,但我我也開放其他方式。嘗試使用模數或fmod,但兩者都給我的程序問題?
int inches, choice, feet, yards;
float centimeters, meters;
float locentimeters, lometers;
int meternum, centnum;
meternum = 39.370;
centnum = .39370;
cout << "Display the entered length in:\n"
<< "1.\tfeet\n"
<< "2.\tyards\n"
<< "3.\tcentimeters\n"
<< "4.\tmeters\n\n"
<< "Enter your choice:\n";
cin >> choice;
cout << "Please enter the length in inches:\n";
cin >> inches;
if (choice == 1)
{
feet = (inches/12);
cout << fixed << showpoint << setprecision(1);
cout << feet << " feet" << inches % 12 << " inches\n";
}
else if (choice == 2)
{
yards = (inches/36);
cout << fixed << showpoint << setprecision(1);
cout << yards << " yards" << inches % 36 << " inches\n";
}
else if (choice == 3)
{
centimeters = (inches/.39370);
cout << fixed << showpoint << setprecision(1);
locentimeters = (inches % centnum);
cout << centimeters << locentimeters << " centimeters\n";
}
else if (choice == 4)
{
meters = (inches/39.370);
cout << fixed << showpoint << setprecision(1);
lometers = (inches % meternum);
cout << meters << lometers << " meters\n";
}
else
cout << "That is an invalid entry.\n";
什麼問題? – NobodyNada 2015-02-17 22:15:41