Can anyone please show me how to do this sample problem?


Shipping Charges

The Fast Freight Shipping Company charges the following rates:
Weight of package (in kilograms) Rate Per 500 Miles shipped
2 Kg or less $1.10
Over 2 Kg but not more that 6 Kg $2.20
Over 6 Kg but not more that 10 Kg $3.70
Over 10 Kg but not more that 20 Kg $4.80


Shipping Rules

FFSC will not ship distances less than 10 miles.
FFSC will not ship distances more than 3000 miles.
FFSC will not ship weights more than 20 Kg.
Do not accept weights of 0 Kg or less
The shipping charge is based on weight in Kg per 500 miles shipped.

Write a program which will:

This is what i need to do:
Display the rate information listed above (don’t worry about borders).
Display the shipping rules
Ask the user for the weight of the package and the distance it is to be shipped.
Prompt the user of shipping rule violations and terminate the program for any invalid inputs
If the input is valid, compute the shipping charges.
Display the charges to the user.

· Display all prices with a $ and 2 decimal places of precision.
· Run the program at least two times
· Provide both source listing and all runtime outputs.

Example:
Weight 3.5 Kg distance 600 miles = $4.40
Weight 1 Kg distance 1001 miles = $3.30
Weight 6.1 Kg distance 499 miles =$3.70
Weight 21 KG distance 500 miles - display a message informing user that package is too heavy to be shipped and exit the program.

Hints
Use nested if statements to handle unacceptable values, various weights and distances
Use modulus to round up distance for 500-mile increments
How much code have you written ?
include <iostream>
using namespace std;
double shipcharge(double kg,int miles){
double sc;
int p5=(miles/500);
if (miles%500>0)p5++;
if(kg<=2)sc=1.1*p5;
else if(kg<6)sc=2.2*p5;
else if(kg<10)sc=3.7*p5;
else if(kg<20)sc=4.8*p5;
return sc;
}
int main ()
{
int d=0,cnt=0;
char kg[10],miles[10];
double w;
cout<<"The Fast Freight Shipping Company rates: \n"
<<"---------------------------------…
<<"Weight of package (in kilograms) Rate Per 500 Miles shipped\n"
<<"2 Kg or less $1.10\n"
<<"Over 2 Kg but not more that 6 Kg $2.20\n"
<<"Over 6 Kg but not more that 10 Kg $3.70\n"
<<"Over 10 Kg but not more that 20 Kg $4.80\n\n";

cout<<"Shipping Rules:\n"
<<"---------------------------------…
<<"FFSC will not ship distances less than 10 miles.\n"
<<"FFSC will not ship distances more than 3000 miles.\n"
<<"FFSC will not ship weights more than 20 Kg.\n"
<<"Do not accept weights of 0 Kg or less\n\n";

while(cnt!=4){
cout<<"Weight of the package :";
gets_s(kg,10);
w=atof(kg);
if (w<=0){cout<<"Weight of package is 0 or less, program will exit now.\n";exit(1);}
else if (w>20){cout<<"Weight of package too heavy, program will exit now.\n";exit(1);}
cout<<"Distance to be shipped :";
gets_s(miles,10);
d=atoi(miles);
if (d<10){cout<<"Ship distance too short, program will exit now.\n";exit(1);}
else if(d>3000){cout<<"Ship distance too long, program will exit now.\n";exit(1);}
cout.precision(2);
cout<<"Shipping charge for "<<w<<" kg for "<<d<<" miles is "<<fixed<<shipcharge(w,d)<<endl;
cnt++;
}
return 0;
}
i have some errors in here and i'm not sure if it's complete

any help would be appreciated
I suppose this will help


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
double shipcharge(double kg,int miles)
{
	double sc;
	int p5=(miles/500);
	if (miles%500>0)p5++;
	if(kg<=2)sc=1.1*p5;
	else if(kg<6)sc=2.2*p5;
	else if(kg<10)sc=3.7*p5;
	else if(kg<20)sc=4.8*p5;
	return sc;
}


int _tmain(int argc, _TCHAR* argv[])
{
	int d=0,cnt=0 , miles;
	double kg  ;
	double w;

	cout<<"The Fast Freight Shipping Company rates: \n"
		<<"---------------------------------\n"
		<<"Weight of package (in kilograms) Rate Per 500 Miles shipped\n"
		<<"2 Kg or less $1.10\n"
		<<"Over 2 Kg but not more that 6 Kg $2.20\n"
		<<"Over 6 Kg but not more that 10 Kg $3.70\n"
		<<"Over 10 Kg but not more that 20 Kg $4.80\n\n";

	cout<<"Shipping Rules:\n"
		<<"--------------------------------\n"
		<<"FFSC will not ship distances less than 10 miles.\n"
		<<"FFSC will not ship distances more than 3000 miles.\n"
		<<"FFSC will not ship weights more than 20 Kg.\n"
		<<"Do not accept weights of 0 Kg or less\n\n";

	while(cnt!=4)
	{
		cout<<"Weight of the package :";
		cin>>kg;
		w = kg;
		if (w <=0 )
		{
			cout<<"Weight of package is 0 or less, program will exit now.\n";
			exit(1);
		}
		else if ( w > 20)
		{
			cout<<"Weight of package too heavy, program will exit now.\n";
			exit(1);
		}
		cout<<"Distance to be shipped :";
		cin>>miles;
		d = miles;
		if (d<10)
		{
			cout<<"Ship distance too short, program will exit now.\n";
			exit(1);
		}
		else if(d>3000)
		{
			cout<<"Ship distance too long, program will exit now.\n";
			exit(1);
		}
		cout.precision(2);
		cout<<"Shipping charge for "<<w<<" kg for "<<d<<" miles is "<<fixed<<shipcharge(w,d)<<endl;
		cnt++;
	}

    
	return 0;
}
when i run this on devc++, it shows that TCHAR* is undeclared

and it forbids declaration of argv with no type

cout undeclared and also cin undeclared

Am i doing something wrong?
you have to include <iostream.h>
Topic archived. No new replies allowed.