secret
anonymous / NeedHelpDebugging
Created

  • Download Gist
NeedHelpDebugging
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
#include <iostream>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
//Named constants residential customers
const double RES_BILL_PROC_FEES = 4.50;
const double RES_BASIC_SERV_COST = 20.50;
const double RES_COST_PREM_CHANNEL = 7.50;
 
//Named constants business customers
const double BUS_BILL_PROC_FEES = 15.00;
const double BUS_BASIC_SERV_COST = 75.00;
const double BUS_BASIC_CONN_COST = 5.00;
const double BUS_COST_PREM_CHANNEL = 50.00;
 
int main()
{
//Variable declaration and intialization
int accountNumber;
char customerType;
int numOfPremChannels;
int numOfBasicServConn;
double amountDue;
 
//declaring file streams
ifstream inFile;
ofstream outFile;
 
//open the file streams
inFile.open("input.txt");
 
//check wheather file exists or not
if(!inFile)
{
cout <<"\n=============== ERROR! ==================\n\n";
cout <<" Could Not Find Input Data File!\n";
cout <<"\n=========================================\n\n\n";
 
return 1;
}
outFile.open("output.txt");
 
 
cout <<"\n==========================================\n\n";
cout <<" PROGRAM TO COMPUTE THE CABLE BILL\n";
cout <<"\n==========================================\n\n";
 
//use while loop to get the acoount numbers and customer type from the file
//Hint:use eof (end of file)
while (!inFile.eof())
{
 
cout<< "The account number is: ";
inFile>> accountNumber;
cout<<accountNumber<<"\n";
 
cout << "The customer type: "
<< "R or r (Residential), "
<< "B or b (Business): ";
 
inFile>> customerType;
//only printed to screen for now
cout << customerType;
 
switch (customerType)
{
case 'r':
case 'R':
cout << "\n\nEnter the number"
<< " of premium channels: ";
cin >> numOfPremChannels;
cout << "\n\n";
 
amountDue = RES_BILL_PROC_FEES
+ RES_BASIC_SERV_COST
+ numOfPremChannels *
RES_COST_PREM_CHANNEL;
 
cout << "Premium Channels = " << numOfPremChannels;
cout << "\nAmount Due = $" << amountDue << endl << endl << endl;
//writing to a outputfile (to be done)
 
break;
 
case 'b':
case 'B':
cout << "\n\nEnter the number of basic "
<< "service connections: ";
cin >> numOfBasicServConn;
 
 
cout << "\nEnter the number"
<< " of premium channels: ";
cin >> numOfPremChannels;
cout << "\n\n";
 
if (numOfBasicServConn<= 10)
amountDue = BUS_BILL_PROC_FEES
+ BUS_BASIC_SERV_COST
+ numOfPremChannels *
BUS_COST_PREM_CHANNEL;
else
amountDue = BUS_BILL_PROC_FEES
+ BUS_BASIC_SERV_COST
+ (numOfBasicServConn - 10) *
BUS_BASIC_CONN_COST
+ numOfPremChannels *
BUS_COST_PREM_CHANNEL;
 
//writing to an ouputfile: to be done, once double-printing is debugged
cout << "Basic Service Connections = " << numOfBasicServConn;
cout << "\nPremium Channels = " << numOfPremChannels;
cout << "\nAmount Due = $" << amountDue << endl << endl << endl;
 
break;
 
default:
 
//writing to an outputfile: to be done, once double-printing is debugged
 
//invalid account prints 2x for some reason, is that fixable?
cout << "\n\nThe account number "<< accountNumber <<" has an invalid customer type";
cout<<"\n\n\n";
cout<<"Account type is invalid";
cout<<"\n\n";
outFile << "The account number " << accountNumber <<" has an invalid customer type";
break;
 
 
}//end switch
}
 
//close inputfile
inFile.close();
 
//close outputfile
outFile.close();
 
 
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.