-nan(ind) and not showing sentinel in .txt?
Nov 17, 2016 at 8:53pm UTC
When I start the program and enter 0 as an account number my average gives me -nan(ind). Is there a way to hide this and have it display "No Data"? Also, this program writes to a .txt and I wanted to know if there was a way to not display the sentinel in the .txt.
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
// Determines a customer's bill for a local cable company
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
int account_Number;
int basic_Service;
int premium_Channels;
double amount_Due;
char customer_Type;
int basic_Connections;
const double RESIDENTIAL_PROCESSING_FEE = 4.50;
const double RESIDENTIAL_BASIC_FEE = 20.50;
const double BUSINESS_PROCESSING_FEE = 15.00;
const double RESIDENTIAL_PREMIUM_PER_CHANNEL = 7.50;
const double BUSINESS_PREMIUM_PER_CHANNEL = 50.00;
const double BUSINESS_BASIC_FEE = 75.00;
const double BUSINESS_ADDITIONAL_CONNECTION = 5.00;
int business_Customer = 0;
int residential_Customer = 0;
int count = 0;
double residential_Total = 0;
double average = 0;
double business_Total = 0;
double total;
cout << "This program computes a cable bill." << endl << endl;
cout << fixed << showpoint << setprecision(2);
ofstream outputFile;
outputFile.open("BillingReport.txt" );
outputFile << fixed << showpoint << setprecision(2);
cout << "Enter account number <an integer>: " ;
cin >> account_Number;
outputFile << "Account number: " << account_Number << endl;
while (account_Number != 0)
{
cout << "Enter customer type: R or r (Residential), B or b (Business): " ;
cin >> customer_Type;
cout << endl;
switch (customer_Type)
{
case 'b' :
case 'B' :
cout << "Enter the number of basic service connections: " ;
cin >> basic_Connections;
cout << "Enter the number of premium channels: " ;
cin >> premium_Channels;
cout << endl;
cout << "Account number: " << account_Number << endl;
if (basic_Connections <= 10)
{
amount_Due = BUSINESS_PROCESSING_FEE + BUSINESS_BASIC_FEE + premium_Channels * BUSINESS_PREMIUM_PER_CHANNEL;
}
else
amount_Due = BUSINESS_PROCESSING_FEE + BUSINESS_BASIC_FEE + (basic_Connections - 10) * BUSINESS_ADDITIONAL_CONNECTION + premium_Channels * BUSINESS_PREMIUM_PER_CHANNEL;
cout << "Amount Due: " << amount_Due;
cout << endl << endl;
outputFile << "Amount due: " << "$" << amount_Due << endl << endl;
business_Customer++;
business_Total += amount_Due;
count++;
break ;
case 'r' :
case 'R' :
cout << "Enter the number of premium channels: " ;
cin >> premium_Channels;
cout << endl;
cout << "Account number: " << account_Number;
cout << endl;
amount_Due = (RESIDENTIAL_PROCESSING_FEE + RESIDENTIAL_BASIC_FEE)
+ premium_Channels * RESIDENTIAL_PREMIUM_PER_CHANNEL;
cout << "Amount Due: " << amount_Due;
cout << endl << endl;
outputFile << "Amount due: " << "$" << amount_Due << endl << endl;
residential_Customer++;
count++;
residential_Total += amount_Due;
break ;
default :
cout << "Invalid customer type." << endl << endl;
}
cout << "Enter account number <an integer>: " ;
cin >> account_Number;
outputFile << "Account number: " << account_Number << endl;
}
cout << endl;
total = (residential_Total + business_Total) / count;
cout << left << setw(35) << "Number of residential customers: " << residential_Customer << endl;
outputFile << endl << left << setw(35) << "Number of residential customers: " << residential_Customer << endl;
cout << left << setw(35) << "Total residential customer bill: " << "$" << residential_Total << endl;
outputFile << left << setw(35) << "Total residential customer bill: " << "$" << residential_Total << endl;
cout << left << setw(35) << "Number of business customers: " << right << business_Customer << endl;
outputFile << left << setw(35) << "Number of business customers: " << business_Customer << endl;
cout << left << setw(35) << "Total business customer bill: " << "$" << business_Total << endl;
outputFile << left << setw(35) << "Total business customer bill: " << "$" << business_Total << endl;
cout << left << setw(35) << "Average bill: " << "$" << total << endl << endl;
outputFile << left << setw(35) << "Average bill: " << "$" << total << endl;
outputFile.close();
return 0;
}
Last edited on Nov 17, 2016 at 9:01pm UTC
Topic archived. No new replies allowed.