我有两个问题。
1.当我用小数转换时,它总是输出为0。
当我不使用小数时,结果很好。
2.我想循环我的结果,这样如果我输入 32 (start_temp) Fahrenheit 我可以增加它直到我的“结束温度”(end_temp) 并且它也转换增加的,如果增量是 10 就说 42从 32 开始,它会将 42 华氏度转换为摄氏温度。
我尝试做一个 for 循环,但没有运气。
请帮忙?
int main()
{
int choice;
cout << "Please Select A Temperature Scale Conversion:\n"<< endl;
cout << "1. Convert F to C" << endl;
cout << "2. Convert C to F\n" << endl;
cout << "Your Choice: ";
cin >> choice;
cout << "Starting Temperature: ";
cin >> start_temp;
cout << "Ending Temperature: ";
cin >> end_temp;
cout << "Temperature Increase: ";
cin >> temp_incr;
if (choice == 1) {
cout << fixed << setprecision(2) << calcFahrenheit(start_temp) << endl;
} else if (choice == 2) {
cout << fixed << setprecision(2) << calcCelsius(start_temp) << endl;
} else {
cout << "You have entered an invalid option." << endl;
}
system("PAUSE");
return 0;
}
float calcFahrenheit(float start_temp) {
float f2c;
f2c = (5.0/9.0) * (start_temp - 32.0);
return f2c;
}
float calcCelsius(float start_temp) {
float c2f;
c2f = (9.0/5.0) * (start_temp + 32.0);
return c2f;
}