Oct 24, 2017 at 10:09am UTC
Here is the code in question. Whenever I compile, it always gives me zeroes for my total cost and discount
#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
//Variables
string clientName;
string type;
int packageWeight;
int shipDistance;
int mileageRate;
float shippingRate;
float discount;
float totalCost;
float intermediateCost;
float discountTotal;
//If, Else for the Cost Rate and Miles Shipped
float calculateRate(int packageWeight, float shippingRate){
if (packageWeight<=2){
shippingRate = 1.10;
}
else
if(packageWeight<=6){
shippingRate = 2.20;
}
else
if(packageWeight<=10){
shippingRate = 3.70;
}
else
if(packageWeight<=20){
shippingRate = 4.80;
}
return shippingRate;
}
//Customer Type and Discount
float evaluateDiscount(string type, int shipDistance){
if(type == "N"){
discount = 0;
}
else
if(type == "R" && shipDistance >= 1000){
discount = 0.05;
}
else
if(type == "V" && shipDistance >= 500 ){
discount = 0.12;
}
else{
cout << "Invalid Customer type, Please try again";
}
return discount;
}
//function to define rate per 500 miles shipped
float calculateMilage(int shipDistance, float mileageRate){
if(shipDistance >= 10 && shipDistance <= 500)
mileageRate = 1;
else
if(shipDistance >= 501 && shipDistance <= 1000)
mileageRate = 2;
else
if(shipDistance >= 1001 && shipDistance <= 1500)
mileageRate = 3;
else
if(shipDistance >= 1501 && shipDistance <= 2000)
mileageRate = 4;
else
if(shipDistance >= 2001 && shipDistance <= 2500)
mileageRate = 5;
else
if(shipDistance>= 2501 && shipDistance <= 3000)
mileageRate = 6;
return 0;
}
int main()
{
cout << "Name" << endl;
cin >> clientName;
cout << "Type" << endl;
cin >> type;
cout << "Weight" << endl;
cin >> packageWeight;
cout << "Distance" << endl;
cin >> shipDistance;
//Discount Math
intermediateCost = shippingRate*mileageRate;
discountTotal = discount*intermediateCost;
totalCost = intermediateCost-(discountTotal);
cout << setprecision(2);
cout << fixed << setw(9) << "Customer" << setw(12) << "Customer" <<
setw(11) << "Package" << setw(12) << "Distance" << setw(22) << "Amount" << endl;
cout << fixed << setw(8) << "Name" << setw(12) << "Type" << setw(12) <<
"Weight" << setw(12) << "Shipped" << setw(12) << "Discount" << setw(9) << "Due"
<< endl;
cout << left << setw(16) << clientName << right << setw(2) << type << setw(12) <<
packageWeight << setw(14) << shipDistance << setw(8) << "$" << setw(4) << discountTotal <<
setw(6) << "$" << setw(4) << totalCost << endl;
return 0;
}
Last edited on Oct 24, 2017 at 10:18am UTC
Oct 24, 2017 at 10:56am UTC
wouldn't discount, shippingRate and mileageRate be calling back to the if/else statements for their respective data? I'm sorry, I'm really new at this.