View Single Post
Old 09-24-2005, 06:38 PM   #1 (permalink)
subodhgupta1
Registered User
 
Join Date: Sep 2005
Posts: 24
subodhgupta1 is on a distinguished road
Shipping Charges

Hi,
Please anybody can look at this program and tell me what is the problem that I can't get the validation to work

The Fast Freight Shipping Company charges the following rates:

Write a program that asks for the weight of the package and the distance it is to be shipped then displays the charges.

Weight of Package (in kilograms) | Rate Per 500 Miles Shipped

2 Kg or less $1.10

Over 2 Kg but not more than 6 Kg $2.20

Over 6 Kg but not more than 10 Kg $3.70

Over 10 Kg but not more than 20 Kg $4.80

Input Validation: Do not accept values of 0 or less for the weight of the package. Do not accept weights of more than 20Kg (this is the maximum weight the company will ship,). Do not accept distances of less than 10 miles or more than 3,000 miles. These are the company’s minimum and maximum shipping distances.

Code:
//---------------------------------------------------------------------------
#include <iostream.h>
#include <iomanip>
#include <cstring>
#include <fstream>
#include <utility>
#include <conio.h>
using namespace std;
//---------------------------------------------------------------------------
int main (void)
{
// Assuming Varibles
double wt_package;
double distance;
double charges;
double rate;

// Asking for inputs.
cout << "Please enter the Wt. Package: ";
cin >> wt_package;
cout << "Please enter the distance: ";
cin >> distance;


// Dertermining the price range.
if (wt_package>0.0 || wt_package<20.0)
// if (wt_package<=0.0){
//cout<< "Please enter the wt. of package above 0.0";
//}else
if (wt_package>0.0 && wt_package<2.0){
rate=1.10;
}else
if (wt_package>2.0 && wt_package<6.0){
rate=2.20;
}else
if (wt_package>6.0 && wt_package<10.0){
rate=3.70;
}else
if (wt_package>10.0 && wt_package<20.0){
rate=4.80;
}//else
// if (wt_package>20.0){
// cout<< "Please enter the wt. of package below or equal to 20.0";
//}


// Dertermining the price range.
if (wt_package>10.0 || wt_package<3000.0)

//cout<< "Please enter the distance above 10.0 and below or equal to 3000.0";

if (distance>10.0 && distance<500.0){
distance=1.0;
}else
if (distance>500.0 && distance<1000.0){
distance=2.0;
}else
if (distance>1000.0 && distance<1500.0){
distance=3.0;
}else
if (distance>1500.0 && distance<2000.0){
distance=4.0;
}else
if (distance>2500.0 && distance<=3000.0){
distance=5.0;
}

// calculating
charges = wt_package * rate * distance;

// Displaying the result.
cout << "\nThe charges for shipping is: $" << charges << endl;
cout << endl << endl << endl << "Press Any Key to Continue...";
getch ();
return 0;
}

Last edited by Valmont; 09-25-2005 at 07:40 AM.
subodhgupta1 is offline   Reply With Quote