dimanche 8 mars 2015

I can't get an answer out of my C++ program

I am using an online compiler (running windows 8 and can't get any others to work). My code runs and compiles and completes, but it doesn't work. It is supposed ask a user for the wind speed and temperature, put them in a formula to calculate wind chill, round them (using a 'homemade' round function), and output the answer. But it gives me nothing.


Thank you for your help.



#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: Ok, so i thought it was something stupid, I'm sorry I am taking a coding class for the first time and having a bit of trouble. So take out the int& and replaced them with just int, but now I get only input to run.


I changed the code a bit.


Aucun commentaire:

Enregistrer un commentaire