Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. // ConsoleApplication2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8. double patientCharges(int, double, double, double);//in-patient
  9. double patientCharges(double, double); //out-patient
  10. char getPatientType();
  11. char option;
  12. int main()
  13. {
  14. double dailyRate=0, addCharges=0, addServices=0, total=0; //declaring doubles
  15. int daysStayed=0;
  16. char option;
  17. option = getPatientType();
  18. if (option == 'I')
  19. {
  20. cout << "How many days did the patient stay in the hospital? \n";
  21. cin >> daysStayed;
  22. while (daysStayed < 0)
  23. {
  24. cout << "Enter an integer greater than 0 \n";
  25. while (!(cin >> daysStayed)) //error handling
  26. {
  27. cin.clear();
  28. cin.ignore('\n');
  29. }
  30. }
  31. cout << "What is the daily rate for this patient? \n";
  32. cin >> dailyRate;
  33. while (dailyRate < 0)
  34. {
  35. cout << "Enter an integer greater than 0 \n";
  36. while (!(cin >> dailyRate))
  37. {
  38. cin.clear();
  39. cin.ignore('\n');
  40. }
  41. }
  42. cout << "Are there any additional medicene for this patient? \n";
  43. cin >> addCharges;
  44. while (addCharges < 0)
  45. {
  46. cout << "Enter an integer greater than 0 \n";
  47. while (!(cin >> addCharges))
  48. {
  49. cin.clear();
  50. cin.ignore('\n');
  51. }
  52. }
  53. cout << "Are there any additional services for this patient(such as lab tests, etc?) \n";
  54. cin >> addServices;
  55. while (addCharges < 0)
  56. {
  57. cout << "Enter an integer greater than 0 \n";
  58. while (!(cin >> addCharges))
  59. {
  60. cin.clear();
  61. cin.ignore('\n');
  62. }
  63. total = patientCharges(daysStayed, addCharges, dailyRate, addServices);
  64. cout << total;
  65. }
  66. total = patientCharges(daysStayed, addCharges, dailyRate, addServices); //using all 4 values to give it to the function with 4 inputs
  67. cout << total;
  68. }
  69. if (option == 'O')
  70. {
  71. cout << "Are there any additional medicene for this patient? \n";
  72. while (!(cin >> addCharges))
  73. {
  74. cin.clear();
  75. cin.ignore('\n');
  76. }
  77.  
  78. cout << "Are there any additional services for this patient(such as lab tests, etc?) \n";
  79. while (!(cin >> addCharges))
  80. {
  81. cin.clear();
  82. cin.ignore(1000, '\n');
  83. cout << "Woah bad data, try again";
  84. }
  85.  
  86. total = patientCharges(addCharges, addServices);
  87. cout << total;
  88. }
  89. return 0;
  90. }
  91.  
  92. double patientCharges(int daysStayed, double dailyRate, double addCharges, double addServices)
  93. {
  94. double perday = daysStayed*dailyRate;
  95. double total = perday + addCharges + addServices;
  96. return total;
  97. }
  98. double patientCharges(double addCharges, double addServices) //both functions for adding the prices
  99. {
  100. double total = addCharges + addServices;
  101. return total;
  102. }
  103. char getPatientType() //small menu with error handling that cant handle integers due to strings not like being compared.
  104. {
  105. cout << "Was this patient admitted as an In-Patient or and Out-Patient? I for in, O for Out \n ";
  106. cin >> option;
  107. while (option != 'I' && option != 'O') //A logical error that works but breaks
  108. {
  109. cout << "Please try again\n";
  110. cin >> option;
  111. }
  112.  
  113. return option;
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement