Theres an error using my driver program?
Hello;
Thanks Cshot and everyone else for your help. This is my problem, i have to input 70 degree, relativr humidity between 15 and 35% and 10 MPH. If I input all of this it should return on the screen as true otherwise any other answer reutrns a false. I must be close because I have no errors shown on my display but its still not right.
Code:
#include <iostream>
#include <string>
using namespace std;
double Okay_to_spray(double);
int main()
{
double temp, rel_humidity, wind_spd;
char spray;
cout << "Input the temperature, relative humidity and the wind speed of our plane: \n";
cin >> temp >> rel_humidity >> wind_spd;
cout << "The plane's temperature is " << temp << " its relative humidity "
<< rel_humidity << " and its wind speed is " << wind_spd << ".\n";
cout << spray << "\n";
return 0;
}
Okay_to_spray()
{
double temp, rel_humidity, wind_spd, spray;
{
if (temp == 70)
if (rel_humidity >= 15 && rel_humidity <= 35)
if (wind_spd == 10)
spray = true;
else
spray = false;
}
return spray;
}
:eek:
Re: Theres an error using my driver program?
Okay, you're declaring two instances of your variables: double temp, rel_humidity, wind_spd; are declared and local to the functions main() and okay_to_spray(). Assigning values to these variables in main() is not going to affect the variables in okay_to_spray()
You have three options:
Make the variables double temp, rel_humidity, wind_spd; global, and remove their declarations from your functions eg:
Code:
#include <iostream>
#include <string>
using namespace std;
bool Okay_to_spray();
double temp, rel_humidity, wind_spd;
int main()
{
cout << "Input the temperature, relative humidity and the wind speed of our plane: \n";
cin >> temp >> rel_humidity >> wind_spd;
cout << "The plane's temperature is " << temp << " its relative humidity "
<< rel_humidity << " and its wind speed is " << wind_spd << ".\n";
cout << (Okay_to_spray()) ? "true" : "false" << "\n";
return 0;
}
bool Okay_to_spray()
{
{
if (temp == 70)
if (rel_humidity >= 15 && rel_humidity <= 35)
if (wind_spd == 10)
return true;
else
return false;
}
}
2. You can pass them to your function okay_to_spray()
Code:
#include <iostream>
#include <string>
using namespace std;
bool Okay_to_spray(double, double, double);
int main()
{
double temp, rel_humidity, wind_spd;
cout << "Input the temperature, relative humidity and the wind speed of our plane: \n";
cin >> temp >> rel_humidity >> wind_spd;
cout << "The plane's temperature is " << temp << " its relative humidity "
<< rel_humidity << " and its wind speed is " << wind_spd << ".\n";
cout << (Okay_to_spray(temp, rel_humidity, wind_spd)) ? "true" : "false" << "\n";
return 0;
}
bool Okay_to_spray(double temperature, double humid, double wind)
{
{
if (temperature == 70)
if (humid >= 15 && humid <= 35)
if (wind == 10)
return true;
else
return false;
}
}
3. You can create a "spray" structure.
Code:
#include <iostream>
#include <string>
using namespace std;
struct spraystr
{
double temperature;
double rel_humidity;
double wind_spd;
};
bool Okay_to_spray(spraystr);
int main()
{
spraystr spray;
cout << "Input the temperature, relative humidity and the wind speed of our plane: \n";
cin >> spray.temperature >> spray.rel_humidity >> spray.wind_spd;
cout << "The plane's temperature is " << spray.temperature << " its relative humidity "
<< spray.rel_humidity << " and its wind speed is " << spray.wind_spd << ".\n";
cout << (Okay_to_spray(spray)) ? "true" : "false" << "\n";
return 0;
}
bool Okay_to_spray(spraystr sprayStructure)
{
{
if (sprayStructure.temperature == 70)
if (sprayStructure.rel_humidity >= 15 && humid <= 35)
if (sprayStructure.wind_spd == 10)
return true;
else
return false;
}
}
You also had other syntatical errors in your code which I fixed, like not calling your function, incorrect return type, not stating the return type, and I don't know what you were doing with the char variable "spray" etc. Personally I'd go with option 2 or 3.