Need help with h/w program

hey guys so i need some help with what im doing wrong here please.

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.,
What output are you getting? What are you expecting?
Do you get any errors? If you don't get any errors then you should try rethinking your program and try another method. I don't know what may cause your problems for now...
KK heres my updated version, seems all well except, when i go to option 1. then type in info and get bak to menu, i click what ever option is just goes to 2. then i click any other one again and goes to 3. wont let me literally choose it just goes from 1,2,3 then exits. any help now ?

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
79
80
81
82
83
84
85
86
87
88
89
90
91
#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; 
{
if (weight <=0)
cout << "Error -1" << endl ;
cout << "Please re-enter weight" << 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;  

default: cout << " You did not enter a 1,2 or 3" << 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;
}
return 0;                                                                       
}
Possible duplicates:
http://www.cplusplus.com/forum/general/70102/
http://www.cplusplus.com/forum/beginner/70094/

Why do you open 3 different threads with the same question?
From what I have read ... You have used the wrong variable for "menu" and you did not declare "menu" in the global scope. There are no matching functions for "tolower". Good Luck.
thanx amilie

and no codekiddy that is not me but what appears to be another student also needing help.
cheers
Oh, excuse me then ;_;
I'm not exactly sure what problem you're having, however i can recommend a few improvements to other parts of the program if you are willing to goto after and rethink these little improvements...

First of all your menu says "fright" not "freight" but that's not really important at.


Secondly if you look in case 1 at the if() i've highlighted the program will ask once again for the value but if 0 is entered a second time the program will continue with 0 which i'm guessing you don't want because of the if() statement in the first place.
I'd suggest changing this to a while() statement so if the value isn't 0 after this it'll loop back through and continue asking until the value != 0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
case '1':                                                                        
cout << "Freight Order" << endl;
cout << "Please input weight of parcel" << endl;
cin >> weight; 
{
if (weight <=0)
cout << "Error -1" << endl ;
cout << "Please re-enter weight" << endl;
cin >> weight;
}
cout << "Please input distance of the shipping" << endl;
cin >> distance;
system ("pause");
switch (tolower( menu() )) 


Finally in your cout statements running through the program you have many spaces where they are not needed. I understand you're wanting this for looks but you could use the \escape routine and insert tabs to move the writing across easy when it's displayed.

 
cout << "\t\t\tWelcome to FastFreight Company" << endl;


this would leave roughly the same space as you have on the front but without having to manually put that many in
Last edited on
Thanks for the reply satsuma, however now that i change the if statement to while, when i input 0 error -1 comes up endlessly and program just displays error -1 throughout the whole window.
Try use cin.getline(weight); rather than cin alone.
sometimes once this has been called before it can mess-up for some reason and not update.

failing this, try cin.ignore(1); before the cin.getline(weight); to pause the program (sometimes it just runs too fast to realise it needs updating cos this works quite often).

Hope tis helps!
Topic archived. No new replies allowed.