Im trying to complete exercises out of a c++ book that does not provide solutions. The first part was to just ask for internet package choice and output the cost of it as well as any additional fees.
The part im having trouble with is:
"Modify the program to show how much money Package A customers would save if they purchased packages B or C
and how much money package B customers would save if they purchased package C. If there is no savings no message should be given.
I think i should do it at the end of the if statements but am not sure and was looking for input or ideas.
Code from part one:
/*
* File: main.cpp
*
*
* Created on July 6, 2011, 10:27 PM
*/
#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;
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 > 10)
{
addCharge = (usage - 10) * 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;
}
/*should the stuff for part 2 go here?*/
writeToFile << name << endl;
writeToFile << choice << endl;
writeToFile << usage << endl;
writeToFile << total << endl;
writeToFile.close();
return 0;
}