help please with program

Dont know whats wrong can i get some help?
program wont run properly so far.

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
72
73
74
75
76
77
78
#include <iostream>
using namespace std;
void printDescription(); 
void calFreightOrder(int,float,float&);

char menu()
{
cout << string( 20, '\n' );
}
int main()
{
char option;
int weight;
float distance;
float orderTotal;
cout << "                     Welcome to FastFreight Company" << endl;   

cout << "You can select option from 1-3 " <<endl;
cout << "    1: Add Fright Order" << endl; 
cout << "    2: Display Freight orders" << endl;
cout << "    3: Exit the system" << endl;
cin >> option;
switch( option )
{    
                                                                     
case '1':                                                                        
cout << "Freight Order" << endl;
cout << "Please input weight of parcel" << endl;
cin >> weight; 
cout << "Please input distance of the shipping" << endl;
cin >> distance;
system ("pause");
switch (tolower( menu() )) 



cout << "                     Welcome to FastFreight Company" << endl;          
cout << "You can select option from 1-3 " <<endl;
cout << "    1: Add Fright Order" << endl; 
cout << "    2: Display Freight orders" << endl;
cout << "    3: Exit the system" << endl;
cin >> option;
switch( option )
break;

case '2':                                                                        
cout << " Your Freight Order is: " << endl;

orderTotal = distance * weight;
cout << "$"; cout << orderTotal << endl;
system ("pause");   
switch (tolower( menu() ))


cout << "                     Welcome to FastFreight Company" << endl;          
cout << "You can select option from 1-3 " <<endl;
cout << "    1: Add Fright Order" << endl; 
cout << "    2: Display Freight orders" << endl;
cout << "    3: Exit the system" << endl;
cin >> option;
switch( option )
break;

case '3':
cout << "Good Bye!" << endl;
system ("pause") ;  
break;  

if (option <1 && option >3)
{
cout << "Error!" ;
cout << "Please select again" ;    
cin >> option ;  
system ("pause");                                                   
}
}
return 0;                                                                       
}





The objective is basically this :

Part 1.
The program should display a menu with the following options:
Welcome to FastFreight Company.
You can select option from 1-3.
1. Add Freight Order
2. Display Freight Orders
3. Exit the system

The program should ask the user to select the option and then act as follows:
Selected Option Action
1 Call the function addFreightOrder and then display the menu to choose again.
2 Call the function, displayOrders and then display the menu to choose again.
3 Exit the program
Any other number Display an error and then display the menu to choose.

Part 2
Write a function to calculate the shipping charges.
It should accept distance and weight, as arguments. Distance and weight can be decimal numbers.
Input Validation:
Invalid Input Error Code
Values of 0 or less for the weight of the
package
-1
Weight of the package more than 20kg -2
Distance less than 8 miles -3
Distance more than 5000 miles -4
Function should use the following rates to calculate the charges:
Weight of Package (in Kilograms) Rate per mile
2 kg or less $0.50
Over 2 kg but not more than 6 kg $0.60
Over 6 kg but not more than 10 kg $0.80
Over 10 kg but not more than 20
kg
$1.10
Once the function is called with required arguments it should return the error code or the charges
accordingly.

2.addFreightOrder:
This function should ask user for a distance to be shipped and the weight of the parcel. Then call the function calculateFreightCharge to calculate the freight charges accordingly.
If the user enters valid inputs, then the function should generate a Freight ID as follows.
Use the first 4 digits on your student ID as the first Freight ID. Increment it by 1 for next freight.
Then add the details of the freight (Freight ID, FreightCharge and FreightStatus Code as ’W’ ) in to a file named freightData.txt. This txt file can be created in the same folder where you have to program stored.
Refer the file freightSampleData.txt to understand the required format for your output file.
If the user enters an invalid data, then the function should display an appropriate error messages. In such instance function should not add any data to freightData.txt file.
3. displayOrders:
This function should display all the freight order details stored in the file freightData.txt. If the file does not exist it should display appropriate error message.,
line 8
cout << string( 20, '\n' );
should be
cout << "20\n";

line 43
1
2
switch( option )
break;


Decent compiler will give you at least an warning about this one.

1
2
case '3':
cout << "Good Bye!" << endl;


You don't have to use switch for every case label, but as many labels as you need in only one switch statement.

Also please not that this place is not a homework service.

I would recommend ( for the future posts) to post the code with decent question about the problem and include error output into your posts as well, that way you may get more atention from other people.
Last edited on
Topic archived. No new replies allowed.