|
From: Shawn <tre...@gm...> - 2008-02-12 05:04:00
|
I'm working with C++ though, my book says that the bool data type is a
built-in type consisting of just two values, the constants true and false.
I have the program compiling without error now, however, it still prints
the last statement even though I didn't enter valid data.
int main()
{
//Declare and initialize variables
float weight = 0.0;
float distance = 0.0;
float shippingRate = 0.0;
float shippingCharges = 0.0;
* bool output = true;*
//Intro
cout<<endl;
cout<<"Thank you for shipping with The Fast Freight Company!!!\n\n";
//Prompt user for the weight of their package
cout<<"Please enter the weight of your pacakge(in grams): ";
cin>>weight;
cout<<endl;
if (weight <= 0 || weight > 20000)
{cout<<"Please enter either a positive number or a weight of 20
kilograms or less for your package.\t\t";
*output == false;*}
//Prompt user for distance the package will travel
cout<<"Please enter the distance the package will travel(in miles): ";
cin>>distance;
cout<<endl;
if (distance < 10 || distance > 3000)
{cout<<"We don't ship to distances of less then 10 miles or more
then 3000 miles.\t\t";
*output == false;*}
//Evaluate weight input
if (weight <= 2000)
shippingRate = 1.10;
else if (weight > 2000 && weight <= 6000)
shippingRate = 2.20;
else if (weight > 6000 && weight <= 10000)
shippingRate = 3.70;
else
shippingRate = 4.80;
//Evaluate distance input
if (distance >= 10 && distance <= 500)
distance = 500;
else if (distance >= 501 && distance <=1000)
distance = 1000;
else if (distance >= 1001 && distance <= 1500)
distance = 1500;
else if (distance >= 1501 && distance <= 2000)
distance = 2000;
else if (distance >= 2001 && distance <= 2500)
distance = 2500;
else
distance = 3000;
//Perform the calculations
shippingCharges = shippingRate * (distance/500);
//Evaluate if output is needed
//if (weight > 0 && weight <= 20000 && distance >= 10 && distance <= 3000)
*if (output == true) *
//Output shipping charges
{cout<<fixed<<showpoint;
cout<<"The total shipping charges for your package is
$"<<setprecision(2)<<shippingCharges<<endl;}
return 0;
}
When I enter 0 for both or just one prompt, the program still displays
both the total shipping charges as $6.60 and the input validation message.
When I uncomment out the *if (weight > 0 && weight <= 20000 && distance
>= 10 && distance <= 3000) *line, it works just fine so I have to be
using bool wrong somehow.
Lloyd wrote:
> //C does not have bool data type
> enum
> {
> FALSE=0,
> TRUE=1
> };
>
> typedef int bool;
>
> int main()
> {
> bool a=TRUE;
> }
>
>
> On Mon, 2008-02-11 at 18:36 -0500, Shawn wrote:
>
>> Thanks, but the compiler is still saying 'TRUE' undeclared (first use
>> this function) and points me to the line where I initialize it to TRUE
>> at the beginning of my program.
>>
>> bool output = TRUE;
>>
>> I thought that as soon as you call bool, the compiler knows it's
>> either going to be true or false?
>>
>> pepone.onrez wrote:
>>
>>> dev...@li...
>>>
>>> On Feb 12, 2008 12:09 AM, Shawn <tre...@gm...> wrote:>
>>>
>>>> but then what would I put just before the total shipping charges
>>>>
>>> line so it wouldn't print?
>>> if(output == TRUE){
>>> //output is TRUE to what you whan
>>> }else{
>>>
>>>
>>> }
>>>
>>> -------------------------------------------------------------------------
>>> This SF.net email is sponsored by: Microsoft
>>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>>> _______________________________________________
>>> Dev-cpp-users mailing list
>>> Dev...@li...
>>> TO UNSUBSCRIBE:
>>> http://www23.brinkster.com/noicys/devcpp/ub.htm
>>> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>>>
>>>
>>> ____________________________________________________________________
>>>
>>> -------------------------------------------------------------------------
>>> This SF.net email is sponsored by: Microsoft
>>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>>>
>>> ____________________________________________________________________
>>>
>>> _______________________________________________
>>> Dev-cpp-users mailing list
>>> Dev...@li...
>>> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>>> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>>>
>>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>>
>
>
> ______________________________________
> Scanned and protected by Email scanner
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
|