2015-03-08 5 views
-4

Я использую онлайн-компилятор (работает с Windows 8 и не могу заставить других работать). Мой код работает, компилируется и завершается, но он не работает. Предполагается спросить пользователя о скорости и температуре ветра, поставить их в формулу для расчета холода ветра, вокруг них (используя «домашнюю функцию») и вывести ответ. Но это ничего не дает.Я не могу получить ответ из моей программы на C++

Благодарим за помощь.

#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; 
} 

Edit: Хорошо, так что я подумал, что это было что-то глупо, я сожалею, что я беру класс кодирования в первый раз и с немного неприятностей. Поэтому вытащите int & и замените их только int, но теперь я получаю только вход для запуска.

Я немного изменил код.

+6

Пожалуйста, перепроверьте свою курсовую работу/учебник/книгу. Ваша основная функция содержит кучу функции _declarations_. Вы не вызываете никаких функций. – Mat

+0

Вы не вызываете функции таким образом: 'int input (int & wspeed, int & tempature);' – PaulMcKenzie

+0

Почему вы передаете все эти бедные 'int' по ссылке? –

ответ

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();

Надеюсь, это поможет. Я не очень хорошо объясняю.

Смежные вопросы