Hi all, brand new here. I'm just finishing up my second project for uni, and have managed to hit a brick wall whilst trying to add the £ sign before variableShippingCost in this line of code:
cout << "The cost of the shipment over " << number << " miles is: " << variableShippingCost << "\n";
If anybody could point me in the right direction I'd be extremely grateful. Here's the rest of the code if it's relevant;
#include <iostream>
#include <cassert>
usingnamespace std;
double number;
float variableShippingCost;
void calculateVariableCost()
{
if (number <= 100)
variableShippingCost = 50 + (number*5.5);
elseif ((number > 100) && (number <= 500))
variableShippingCost = 50 + (100 * 5.5) + ((number - 100)*4.0);
elseif (number > 500)
variableShippingCost = 50 + (100 * 5.5) + (400 * 4.0) + ((number - 500)*2.5);
}
int main()
{
cout << "Enter distance in miles: ";
cin >> number;
if (number <= 0)
cout << "ERROR: The distance must be a positive value.";
else
calculateVariableCost();
cout << "The cost of the shipment over " << number << " miles is: " << variableShippingCost << "\n";
system("PAUSE");
return 0;
}
Also, just a quick unimportant question, I was previously lead to believe that procedures must be 'prototyped' before being called, is this true? If so, could somebody tell me why the code above works without prototype for 'calculateVariableCost'?
I did try that but it appears Visual Studio doesn't recognize the £ symbol. Managed to resolve the issue by using (char)156 instead of £.
I've now encountered another problem, when I input a negative value as the distance in miles, I am getting the following output:
1 2 3 4
Enter distance in miles: -20
ERROR: The distance must be a positive value.The cost of the shipment over -20 m
iles is: £0
Press any key to continue . . .
Really baffled as to why it is printing "The cost of the shipment over -20 m
iles is: £0" even when number is <= 0... :(
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int main()
{
cout << "Enter distance in miles: ";
cin >> number;
if (number <= 0)
cout << "ERROR: The distance must be a positive value.";
elseif (number > 0)
calculateVariableCost();
cout << "The cost of the shipment over " << number << " miles is: " << (char)156 << variableShippingCost << "\n";
system("PAUSE");
return 0;
}