我正在使用在线编译器(运行Windows 8,并且无法让任何其他人工作)。我的代码运行并编译和完成,但它不起作用。假设询问用户风速和温度,将它们放入公式计算风寒,围绕它们(使用自制的圆形功能)并输出答案。但它什么都没给我。
感谢您的帮助。
#include <iostream>
#include <cmath>
using namespace std;
int input (int wspeed, int tempature);
int calculate (int tempature, int wspeed, int windChill);
int trunkate (int windChill, double wchill);
int output (int tempature, int wspeed, int windChill);
int advisoryWarning (int windChill);
int main()
{
int wspeed=0, tempature=0, windChill=0;
double wchill=0;
int input (int& wspeed, int& tempature);
int calculate (int& tempature, int& wspeed, int& windChill);
int trunkate (int& windChill, double& wchill);
int output (int& tempature, int& wspeed, int& windChill);
int advisoryWarning (int& windChill);
return 0;
}
int input (int& wspeed, int& tempature)
{
cout<<"This is the input function\nPlease input the tempature outside in fahrenheit."<<endl;
cin>>tempature;
cout<<"Please input wind speed in miles per hour."<<endl;
cin>>wspeed;
if(tempature<-40||tempature>40)
{
cout<<"Please input a valid tempature between -40 and 40"<<endl;
cin>>tempature;
}
if(wspeed<0||wspeed>60)
{
cout<<"Please input a valid wind speed between 0 and 60 mph"<<endl;
cin>>wspeed;
}
return 0;
}
int calculate (int& tempature, int& wspeed, double& wchill)
{
cout<<"\nThis is calculating\n";
wchill=35.74+0.6215*(tempature)-35.75*(pow(wspeed, 0.16))+0.4275*tempature*pow(wspeed, 0.16);
return wchill;
}
int trunkate (int& windChill, int& wchill)
{
//This is the round function
cout<<"\nThis is the trunkator function\nThis is the exact answer: " << wchill<<endl;
if(wchill<0)
wchill=wchill-0.5;
else
wchill=wchill+0.5;
cout<<"this is windchill plus or minus a half: "<<wchill<<endl;
windChill=wchill;
cout<<"this is the final answer: "<<windChill<<endl;
return windChill;
}
int output (int& tempature, int& wspeed, int& windChill)
{
cout<<"\nthis is the output function\n";
cout<<"Tempature entered: "<<tempature<<endl<<"Wind Speed entered: "<<wspeed<<endl<<"Wind Chill: "<<windChill<<endl<<endl;
cout<<"Calling the advisory output function...";
return 0;
}
int advisory (int& windChill)
{
if(windChill<-50)
cout<<"Life threatening: Fostbite can occur within 5 minutes.";
else if (windChill<-30)
cout<<"Danger: Frostbite can occur within 10 minutes.";
else if (windChill<-15)
cout<<"Warning: Frostbite can occur within 30 minutes.";
else if (windChill<20)
cout<<"Advisory: Frostbite can occur with extended exposure.";
else if (windChill<40)
cout<<"Notice: Wear cold weather clothing as needed for comfort.";
else
cout<<"No significant cold weather risk.";
return 0;
}
编辑:好的,所以我认为这是愚蠢的事情,对不起,我第一次参加编码课并遇到一些麻烦。所以拿出int&amp;并用int替换它们,但现在我只输入运行。
我稍微更改了代码。
答案 0 :(得分:1)
int main()
{
int wspeed=0, tempature=0, windChill=0;
double wchill=0;
input (int& wspeed, int& tempature);
calculate (int& tempature, int& wspeed, int& windChill);
trunkate (int& windChill, double& wchill);
output (int& tempature, int& wspeed, int& windChill);
advisoryWarning (int& windChill);
return 0;
}
我为你修好了你的主要功能。当您调用其他函数时,不要调用函数的类型。当你创建一个名为
的函数时int function(){}
int只是返回类型。当您调用另一个函数时,您只需要添加该函数的名称。在你的int main中,你只需要使用function();
进行调用希望这会有所帮助。我不太擅长解释。