-
-
Save drmmr763/3092284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Programming Assignment #8 | |
// CellBillFun | |
//Author: Jess Darling | |
//Date: July 8, 2012 | |
#include <stdlib.h> | |
#include <iostream> | |
#include <iomanip> | |
#include <string> | |
using namespace std; | |
const double R_Srv_Fee = 10.00; | |
const double P_Srv_Fee = 25.00; | |
const int base_R_min = 50; | |
const int base_Pday_min = 75; | |
const int base_Pnight_min = 100; | |
const double over_RbaseFee = .20; | |
const double over_PbaseDayFee = .10; | |
const double over_PbaseNFee = .05; | |
double calcRegBill (int Rmins); | |
double calcPremBill (int Dmins, int Nmins); | |
void printBill(string acctnumber, char srvtype, int totalmin, double totalDue); | |
int main() | |
{ | |
string acctnumber; | |
char srvtype; | |
int Rmins; | |
int Dmins; | |
int Nmins; | |
int totalmin; | |
double totalDue; | |
cout << fixed << showpoint; | |
cout << setprecision (2); // set PREcision, not set PERcision. - CW | |
cout << "Enter Account Number ( 0 to quit): " << endl; | |
cin >> acctnumber; | |
cout << endl; | |
cout << "Enter Service Type: R or r (Regular), P or p (Premium): " << endl; | |
cin >> srvtype; | |
cout << endl; | |
switch (srvtype) | |
{ | |
case 'r': | |
case 'R': | |
cout << "Enter minutes used: " << endl; | |
cin >> Rmins; | |
totalDue = calcRegBill(Rmins); | |
totalmin = Rmins; | |
break; // added breaks to the switch statement. - CW | |
case 'p': | |
case 'P': | |
cout << "Enter day minutes used: " << endl; | |
cin >> Dmins; | |
cout << "Enter night minutes used: " << endl; | |
cin >> Nmins; | |
totalDue = calcPremBill(Dmins,Nmins); | |
totalmin = Dmins + Nmins; | |
break; // added breaks to the switch statement. - CW | |
} | |
printBill(acctnumber, srvtype, totalmin, totalDue); | |
system("PAUSE"); | |
return 0; // use a ; not a : - CW | |
} | |
double calcRegBill (int Rmins) | |
{ | |
double amtDue; | |
if (Rmins <= base_R_min) | |
amtDue = R_Srv_Fee; | |
else | |
amtDue = R_Srv_Fee + ((Rmins - base_R_min) * over_RbaseFee); | |
return (amtDue); | |
} | |
double calcPremBill (int Dmins, int Nmins) | |
{ | |
double amtDue; | |
if (Dmins > base_Pday_min) | |
amtDue = P_Srv_Fee + ((Dmins - base_Pday_min) * over_PbaseDayFee); | |
if (Nmins > base_Pnight_min) // didn't close this correctly - CW | |
amtDue = P_Srv_Fee + ((Nmins - base_Pnight_min) * over_PbaseNFee); // wrong variable name here. - CW | |
else | |
amtDue = P_Srv_Fee; | |
return (amtDue); | |
} | |
void printBill(string acctnumber, char srvtype, int totalmin, double amtDue) | |
{ | |
cout << "Jess Darling" << endl; | |
cout << "Account Number: " | |
<< acctnumber << endl; | |
cout << "Service Type: " | |
<<srvtype << endl; | |
cout << "Minutes Used: " | |
<< totalmin << endl; | |
cout << "Amount Due: $" | |
<<amtDue << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment