Hey there, I'm a C++ noob but I think I'm slowly beginning to understand it.
A task I've been set asks me to put together a little program which will calculate shipping cost given that;
Up to 100 miles = £5 per mile
101 to 500 miles = £4 per mile
501+ = £3 per mile
I wrote my code for this in C++ but I'm getting two errors, which I can't seem to solve even with some Googling, here's my code:
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
|
/* Shipping cost calculation program */
#include <iostream>
using namespace std;
//constants
int fixedShippingCost = 50;
//variables
float variableShippingCost;
float ShippingDistance;
float ShippingCost;
//function prototypes
void calculateShippingCost();
int main()
{
cout << "Enter the distance in miles: ";
cin >> ShippingDistance;
if (ShippingDistance <= 0);
cout << "Error: The distance should be a positive value.";
else
void calculateShippingCost();
cout << "The cost of shipment is: £ "; ShippingCost; ".";
return (0);
}
/*Calculate the cost of shipment*/
void calculateShippingCost
{
if ShippingDistance <=100;
variableShippingCost = (shippingDistance * 5);
ShippingCost = variableShippingCost+fixedShippingCost;
else if (500 <= shippingDistance > 100);
variableShippingCost = (((shippingDistance-100)*4)+500);
ShippingCost = variableShippingCost + fixedShippingCost;
else if (shippingDistance > 500);
variableShippingCost = (((shippingDistance-500)*3)+2100);
ShippingCost = variableShippingCost + fixedShippingCost;
}
|
The errors I'm getting are as follows:
line 27
error C2181: illegal else without matching if
line 38
error C2470: 'calculateShippingCost' : looks like a function definition, but there is no parameter list; skipping apparent body |
For the first error, I have an "if" three lines above, and for the second error I have another task of mine which I used as a reference for the syntax and it worked there.
I'm probably missing something obvious, so I'm sorry for that but anyone willing to help would be doing me a huge favour :).