Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. /*This program shows a report for a phone company displaying customer information
  8. Written by Alyssa Lunney*/
  9.  
  10. int main()
  11. {
  12.  
  13. //Housekeeping
  14. string custName;
  15. int noTexts, noCust=0;
  16. double textCharge, custBill, total = 0.0, average;
  17. const double RATE = 29.00;
  18.  
  19. ofstream fout("phoneBill.dat");
  20.  
  21. fout << fixed << setprecision(2);
  22. if (!fout.is_open())
  23. {
  24. cout << "Error Opening the File!";
  25. system("pause");
  26. exit(-1);
  27. }
  28.  
  29. cout << fixed << setprecision(2);
  30. cout << "Phone Bill" << endl << endl;
  31.  
  32. //Input
  33.  
  34. fout << left << setw(16) << "Customer";
  35. fout << right << setw(16) << "# Text";
  36. fout << setw(16) << "Text";
  37. fout << setw(16) << "Customer" << endl << endl;
  38.  
  39. fout << left << setw(16) << "Name";
  40. fout << right << setw(16) << "Msgs";
  41. fout << setw(16) << "Msgs";
  42. fout << setw(16) << "Bill" << endl;
  43.  
  44. cout << "Please enter customer name or crtl-z: ";
  45. getline(cin, custName);
  46. cout << endl;
  47.  
  48. while (!cin.eof())
  49. {
  50. while (custName.length() == 0)
  51. {
  52. cout << "You must enter a name ";
  53. getline(cin, custName);
  54. }
  55. cout << "Please enter number of text messages sent ";
  56. cin >> noTexts;
  57. cout << endl;
  58.  
  59. // this still has && instead of || or all &&. This is incorrect.
  60. while (noTexts < 0 || noTexts > 500 || cin.fail())
  61. {
  62. cin.clear();
  63. cin.ignore(80, '\n');
  64. cout << "Please enter a whole number value between 0 and 500 ";
  65. cin >> noTexts;
  66. fout << right << setw(48) total += custBill;
  67. fout << setw(48) << average = total / noCust;
  68. fout << left << setw(16) << "Total Bill";
  69. fout << setw(16) << "Average Bill";
  70. }
  71. cin.ignore(80, '\n');
  72.  
  73. //this is per customer
  74. if (noTexts > 10 && noTexts <= 100)
  75. {
  76. textCharge = 0.25;
  77. }
  78.  
  79. else if (noTexts > 100)
  80. {
  81. textCharge = 0.50;
  82. }
  83. else
  84. {
  85. textCharge = 0.00;
  86. }
  87. // make sure you intialize before fout
  88. textCharge = noTexts*textCharge;
  89. custBill = textCharge + RATE;
  90.  
  91. // everything but your input should be above this fout statement
  92. fout << left << setw(16) << custName;
  93. fout << right << setw(16) << noTexts;
  94. fout << setw(16) << textCharge;
  95. fout << setw(16) << custBill << endl << endl;
  96.  
  97. noCust++;
  98. cout << "Please enter customer name or crtl-z: ";
  99. getline(cin, custName);
  100. cout << endl;
  101. }
  102.  
  103. //Proccessing
  104.  
  105. if (noCust > 0)
  106. {
  107. //print to fout so that is the footer on your bill
  108. fout << "Total Bills " << endl;
  109. fout << "Average Bills ";
  110. //calculate the average
  111. fout << "Thank you";
  112.  
  113.  
  114. }
  115.  
  116.  
  117. //Output
  118.  
  119.  
  120. system("type phoneBill.dat");
  121. system("pause");
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement