Let me help a bit, because this is getting a bit unreadable:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
if (WEIGHT > 0 && WEIGHT <= 20)
COST = 14.95;
else if (WEIGHT > 20 && WEIGHT <= 50)
COST = 19.95;
else if (WEIGHT > 50 && WEIGHT <= 100)
COST = 29.95;
else if (WEIGHT > 100 && WEIGHT <= 200)
COST = 49.95;
else if (WEIGHT > 200)
COST = 49.95;
else if (WEIGHT < 0)
{
cout << "Please enter a valid weight above 0 lbs \n";
VALIDdata = false;
system("pause");
return 0;
}
|
That is, I think, more acceptable and readable.
One more thing, I see you don't really check if weight == 0, so all that would be skipped if the user entered a zero.
Another tip, if you put the WEIGHT < 0 at the top of the list of conditionals, you can drop the lower limits of each of the checks, since the if statements are chained, they are one long list, each being part of the whole, progressing upwards.
To illustrate, say I'm range checking a number and the ranges are defined as 0 - 9, 10 - 19, 20 - 29 and it's assured the number is >= 0 and < 30:
1 2 3 4 5 6 7 8
|
if ( num < 10 )
do this;
else if (num < 20)
do this instead;
else if( num < 30 )
do this otherwise;
execution picks up here.
|
If it finds the number is < 10, it will execute the first if statement and then drop down to the pickup line.
Just a tip to help make your code a little easier to read.
Also, you could indent a single tab to minimize lines wrapping over to the next line.
On to your current issues, this is what I'm getting for warnings/errors:
1 2 3 4 5 6
|
1>c:\users\roberts\documents\visual studio 2010\projects\testbed\testbed\test.cpp(72): warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\users\roberts\documents\visual studio 2010\projects\testbed\testbed\test.cpp(83): warning C4806: '==' : unsafe operation: no value of type 'bool' promoted to type 'char' can equal the given constant
1>c:\users\roberts\documents\visual studio 2010\projects\testbed\testbed\test.cpp(89): warning C4806: '==' : unsafe operation: no value of type 'bool' promoted to type 'char' can equal the given constant
1>c:\users\roberts\documents\visual studio 2010\projects\testbed\testbed\test.cpp(95): warning C4806: '==' : unsafe operation: no value of type 'bool' promoted to type 'char' can equal the given constant
1>c:\users\roberts\documents\visual studio 2010\projects\testbed\testbed\test.cpp(110): warning C4806: '==' : unsafe operation: no value of type 'bool' promoted to type 'int' can equal the given constant
1>c:\users\roberts\documents\visual studio 2010\projects\testbed\testbed\test.cpp(117): warning C4806: '==' : unsafe operation: no value of type 'bool' promoted to type 'int' can equal the given constant
|
It sees that semi-colon as the end of the if statement body, so the code within the brackets is executed regardless of the validity of baseprice.
The rest is a type mismatch. You shouldn't compare a bool to a character and that is probably throwing off the comparisons. A bool is either 0 for false or not 0 for true.