Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <fstream>
- using namespace std;
- /*This program shows a report for a phone company displaying customer information
- Written by Alyssa Lunney*/
- int main()
- {
- //Housekeeping
- string custName;
- int noTexts, noCust=0;
- double textCharge, custBill, total = 0.0, average;
- const double RATE = 29.00;
- ofstream fout("phoneBill.dat");
- fout << fixed << setprecision(2);
- if (!fout.is_open())
- {
- cout << "Error Opening the File!";
- system("pause");
- exit(-1);
- }
- cout << fixed << setprecision(2);
- cout << "Phone Bill" << endl << endl;
- //Input
- fout << left << setw(16) << "Customer";
- fout << right << setw(16) << "# Text";
- fout << setw(16) << "Text";
- fout << setw(16) << "Customer" << endl << endl;
- fout << left << setw(16) << "Name";
- fout << right << setw(16) << "Msgs";
- fout << setw(16) << "Msgs";
- fout << setw(16) << "Bill" << endl;
- cout << "Please enter customer name or crtl-z: ";
- getline(cin, custName);
- cout << endl;
- while (!cin.eof())
- {
- while (custName.length() == 0)
- {
- cout << "You must enter a name ";
- getline(cin, custName);
- }
- cout << "Please enter number of text messages sent ";
- cin >> noTexts;
- cout << endl;
- // this still has && instead of || or all &&. This is incorrect.
- while (noTexts < 0 || noTexts > 500 || cin.fail())
- {
- cin.clear();
- cin.ignore(80, '\n');
- cout << "Please enter a whole number value between 0 and 500 ";
- cin >> noTexts;
- fout << right << setw(48) total += custBill;
- fout << setw(48) << average = total / noCust;
- fout << left << setw(16) << "Total Bill";
- fout << setw(16) << "Average Bill";
- }
- cin.ignore(80, '\n');
- //this is per customer
- if (noTexts > 10 && noTexts <= 100)
- {
- textCharge = 0.25;
- }
- else if (noTexts > 100)
- {
- textCharge = 0.50;
- }
- else
- {
- textCharge = 0.00;
- }
- // make sure you intialize before fout
- textCharge = noTexts*textCharge;
- custBill = textCharge + RATE;
- // everything but your input should be above this fout statement
- fout << left << setw(16) << custName;
- fout << right << setw(16) << noTexts;
- fout << setw(16) << textCharge;
- fout << setw(16) << custBill << endl << endl;
- noCust++;
- cout << "Please enter customer name or crtl-z: ";
- getline(cin, custName);
- cout << endl;
- }
- //Proccessing
- if (noCust > 0)
- {
- //print to fout so that is the footer on your bill
- fout << "Total Bills " << endl;
- fout << "Average Bills ";
- //calculate the average
- fout << "Thank you";
- }
- //Output
- system("type phoneBill.dat");
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement