Originally posted by mikezmr2
ok this is starting to get irrating. i have these as constansts:
// constants for under 50,000 miles;
const double Carbon_Monoxide = 3.4;
const double Hydro_Carbons = 0.31;
const double Nitrogen_Oxides = 0.4;
const double Nonmethane_HydroCarbons = 0.25;
I also have these labeled as "1" , "2" , "3", and "4" (same order)
one of my input varialbes is "pollutant" (can equal anthing 1 , 0.4
etc. etc.
my if and then statement looks like this:
if(miles < 50000)
dataOK = true;
else
dataOK = false;
if (dataOK) // start of true value;
if(number >= pollutant)
{
cout << "passed emissions " << endl;
}
else
{
cout << "emissions level exceeded " << endl;
}
The problem is this bug keeps telling me that if I enter number 2
which would be "Hydro_Carbons = 0.31"
and "pollutant" = 0.42
it becomes true when it should be false... weird to me cause i'm a beginner and can't fix it :P << all numbers were set to doubles>> if that matters at all.
Well, you could tighten the code up by:
Code:
dataOK = false;
if (miles < 50000)
{
dataOK = true;
if (number >= pollutant)
cout << "Passed emissions";
else
cout << "Emission levels exceeded";
}
The problem might be where you assign number to the various pollutants. It may be checking if 2 is greater than or equal to 0.42, which of course it is. Assigning 2 to "Hydrocarbons = 0.31"? As written, you're assigning a string to a numeric variable. That specifically may not be the problem, but assigning the 2 might be. 2 is a literal constant, not a variable. You can't have
double hydrocarbons = 0.31 and double 2 = hydrocarbons. Without seeing your code there, it's hard to say.