-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaimProcess.c
More file actions
202 lines (185 loc) · 6.2 KB
/
claimProcess.c
File metadata and controls
202 lines (185 loc) · 6.2 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdbool.h>
#include "details.h"
/*Below is the second function for our system, this
is used to file the claims for the subscribers*/
claimProcess() {
FILE* file;
FILE* f;
FILE* F;
/*we open the files in reand and append+write more respectively*/
file = fopen("details.txt", "r");
f = fopen("claim.txt", "r");
F = fopen("updatedclaims.txt", "w");
int ch, j, id, counter = 0;
int roomType, roomCost=0, days, ssCost, surgicalFees, other,borne;
bool flag=false;
if (file == NULL) {
printf("\nFile not found");
return 0;
}
else {
//we count number of lines
for (ch = getc(file); ch != EOF; ch = getc(file))
if (ch == '\n')
counter += 1;
printf("\nEnter ID: ");
scanf_s("%03d", &id);
//we use those number of lines to set the limit for the loop
for (j = 0; j < counter; j++) {
if (detail[j].id == id) { //if input matches id in the file, flag is set to true, else it is set to false
flag = true;
break;
}
}
if (flag == false) {
printf("Subscriber/ID does not exist");
return 0; //maybe try break
}
/*after id is verified, we print the users name and age*/
printf("\n\n Name: %s", detail[j].name);
printf("\n Age: %d", detail[j].age);
printf("\n\nEnter the following claim detais:");
while (flag==true){ //here we will ask for details of the room and other relevant data that is needed
printf("\n\nType of room stayed in:\n1)Normal Room\n2)Intensive Care Unit\nOption: ");
scanf_s("%d", &roomType);
if (detail[j].age > 0 && detail[j].age < 21) {
//since the options differe for each age group, we divide the options for each age group
if (detail[j].choice == 1) {
if (roomType == 1) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 120;
}
else if (roomType == 2) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 250;
}
else {
printf("\n\nInvalid Room type, please try again");
continue;
}
}
else if (detail[j].choice == 2) {
if (roomType == 1) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 150;
}
else if (roomType == 2) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 400;
}
else {
printf("\n\nInvalid Room type, please try again");
continue;
}
}
else { //if choice==3
if (roomType == 1) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 200;
}
else if (roomType == 2) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 700;
}
else {
printf("\n\nInvalid Input, please try again");
continue;
}
}
}
else if (detail[j].age > 20 && detail[j].age < 41) {
if (detail[j].choice == 1) {
if (roomType == 1) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 150;
}
else if (roomType == 2) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 400;
}
else {
printf("\n\nInvalid Room type, please try again");
continue;
}
}
else {//if choice==2
if (roomType == 1) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 200;
}
else if (roomType == 2) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 700;
}
}
}
else {//age above 40
if (roomType == 1) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 200;
}
else if (roomType == 2) {
printf("\n\nEnter days stayed in room: ");
scanf_s("%d", &days);
roomCost = 700;
}
else {
printf("\n\nInvalid Input, please try again");
continue;
}
}
printf("\nEnter cost of supplies & services: ");
scanf_s("%d", &ssCost);
printf("\nEnter Surgical fees: ");
scanf_s("%d", &surgicalFees);
printf("\nOther extra charges: ");
scanf_s("%d", &other);
//we calculate the claim amount and is saved to claim structure
claim[j].claimedAmount = (roomCost * days) + ssCost + surgicalFees + other;
// here is when we check if expense is higher than eligible claim amount
if (claim[j].claimedAmount >= claim[j].remainingAmount) {
//if expense is higher than claimable amount
borne = claim[j].claimedAmount - claim[j].remainingAmount;
claim[j].remainingAmount = 0;
claim[j].claimedAmount = claim[j].claimedAmount - borne;
printf("\n\nName: %s\nID: %03d\nClaim Year: %d\nClaimed Amount: %d\nRemaining balance: %d\nAmount to be borne by subscriber: %d", detail[j].name, detail[j].id, claim[j].claimYear, claim[j].claimedAmount,claim[j].remainingAmount, borne);
}
else {
//if claimable amount is higher than expense
claim[j].remainingAmount -= claim[j].claimedAmount;
printf("\n\nName: %s\nID: %03d\nClaim Year: %d\nClaimed Amount: %d\nRemaining amount: %d", detail[j].name, detail[j].id, claim[j].claimYear, claim[j].claimedAmount, claim[j].remainingAmount);
}
/*finally we assign the id from detail struct to claim struct so it can be saved
to file and be able to identify who's information belongs to who, and print those details to claim.txt file*/
uclaim[j].id = claim[j].id;
uclaim[j].claimYear = claim[j].claimYear;
uclaim[j].claimedAmount = claim[j].claimedAmount;
uclaim[j].remainingAmount = claim[j].remainingAmount;
claim[j].id = detail[j].id;
for (j = 0; j < counter; j++) {
fprintf(F, "%03d\t%d\t%d\t%d\n", uclaim[j].id, uclaim[j].claimYear, uclaim[j].claimedAmount, uclaim[j].remainingAmount);
}
//fprintf(f, "%03d\t%d\t%d\t%d\n", claim[j].id, claim[j].claimYear, claim[j].claimedAmount, claim[j].remainingAmount);
break;
}
}
fclose(F);
fclose(file);
fclose(f);
return 0;
}
//changed claim.txt to w only and the for loop below
//changed scanf to gets