I created a program that ask a user to pick a service package and tell them how much it is going to cost, what i cant figure out is how to get the program to tell them how much they would have saved if they had gone with a different package.
ill put comments in the code where im having problems, its near the bottom of main.
ive tried putting the different calculations in the actual package choice and at the end, i think they should go at the end but if not could someone guide me in the right direction.
#include <iostream>
#include<fstream>
using namespace std;
int main()
{
cout << "Package A: $9.95 per month, 10 hours access, $2.00 per hour after that" << endl;
cout << "Package B: $14.95 per month, 20 hours access, $1.00 per hour after that" << endl;
cout << "Package C: $19.95 per month, unlimited acces" << endl << endl;
char choice;
double usage, charges, packA = 9.95, packB = 14.95, packC = 19.95, hoursA = 2.00,
hoursB = 1.00, addCharge = 0.0, total = 0.0, savings1 = 0.0, savings2 = 0.0;
string name;
ofstream writeToFile;
writeToFile.open("charges.txt");
// cout << "What is your full name?" << endl;
// getline(cin, name);
cout << "Would you like package A, B or C?" << endl;
cout << "Package: ";
cin >> choice;
cout << "How many hours did you use the internet?" << endl;
cout << "Usage: ";
cin >> usage;
if ((choice == 'a') || (choice == 'A'))
{
charges = packA;
cout << "\nMonthly Charge $" << charges << endl;
if (usage > 10)
{
addCharge = (usage - 10) * hoursA;
cout << "Additional charge $" << addCharge << endl;
}
total = charges + addCharge;
cout << "Total Charges: $" << total << endl;
}
else if ((choice == 'b') || (choice == 'B'))
{
charges = packB;
cout << "\nMonthly Charge $" << charges << endl;
if (usage > 20)
{
addCharge = (usage - 20) * hoursB;
cout << "Additional Charges: $" << addCharge << endl;
}
total = charges + addCharge;
cout << "Total Charges: $" << total << endl;
}
else if ((choice == 'c') || (choice == 'C'))
{
charges = packC;
cout << "\nTotal Charges: $" << charges << endl;
}
// this is the part where im trying to output savings
if (total > packA)
{
savings1 = total - packA;
savings2 = total - packC;
cout << "\nIf you had gone with package B you would have saved $" << savings1 << endl;
//nested if else to stop a negative savings from appearing
if (savings2 < 0)
{
cout << "";
}
else
{
cout << "\nIf you had gone with package C you would have saved $" << savings2 << endl;
}
}
else
{
savings2 = total - packB;
cout << "If you went with package C you would have saved $" << savings2 << endl;
}
// end of problem with savings area
writeToFile << name << endl;
writeToFile << choice << endl;
writeToFile << usage << endl;
writeToFile << total << endl;
writeToFile.close();
return 0;
}