Overloading functions

Write your question here.
Guys this code is supposed to be simple and call the overloaded function accordingly, yet when I execute this code it does not give me the results I am looking for. There seems to be a logic error with my conditional statements and it only calculates the price of dhl courier.
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
  #include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
//declare the functions for calculation of cost

 double calcPostage(double weight, int zone) // GlobalMail cost calculation
{ double cost;
    if (zone > 0 && zone < 4 )
    { cost =  108 * weight; }
    else 
    {
    if (zone > 3 && zone < 7)
    { 
        cost = 130 * weight; } 
        
    }
    
    return cost; 
    }
double calcPostage(double weight, double length, double width, double height) //DHL cost calculation
  { double cost1;
      double volumetric;
      volumetric = (length * width * height)/5000;
      if (volumetric > weight)
      { cost1 = volumetric * 70; }
      else { cost1 = weight * 70; } 
      
   return cost1; 
  }

int main()
{
  char entered; double eWeight; int eZone; double price; double elength; double eHeight; double eWidth; 
   cout << "Select postage service provider: "<< endl; 
   cout << "Press 'd' for DHL or 'g' for GlobalMail " <<endl; 
   cin >> entered; 
   cout << "Please enter the weight of your parcel: " << endl; 
    cin >> eWeight; 
  
   if (entered == 'd' || 'D')
    {  
        cout <<"Please enter length, width and height respectively and press enter afterwards:"  <<endl; 
        cin >> elength;
        cin >> eWidth;
        cin >> eHeight; 
        
        price = calcPostage(eWeight, elength,eWidth, eHeight); 
    }
 else 
    {
   if (entered == 'g' || 'G')
    { 
       cout <<"Please enter postage zone between 1 and 6:"  <<endl; 
       cin >> eZone;
       price = calcPostage(eWeight, eZone); }
    else 
     { 
     cout << "Please select a valid service provider" << endl;
      }
       
        } 

     cout << "The courier price to London is  R"  << price << endl;  
   
	return 0;
}
Lines 41 and 52: All conditions in an if statement must stand on their own.
Change to
if (entered == 'd' || entered == 'D')

In calcPostage, what happens when zone is below 0 or above 7?
Last edited on
when zone is below 0 or above 7 the program is not supposed to calculate a cost or give a zero as a price
Topic archived. No new replies allowed.