-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (44 loc) · 1.2 KB
/
Copy pathmain.cpp
File metadata and controls
60 lines (44 loc) · 1.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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main() {
ifstream file("hospitals.txt");
if(!file){
cout<<"File not opened\n";
return 0;
}
string userLocation, userTest;
cout<<"Enter your location: ";
getline(cin,userLocation);
cout<<"Enter test name (CBC/XRay/ECG etc): ";
getline(cin,userTest);
string line;
string hospital, location, test;
int price;
int minPrice = 999999;
string bestHospital = "";
while(getline(file,line)){
if(line=="") continue;
stringstream ss(line);
getline(ss,hospital,',');
getline(ss,location,',');
getline(ss,test,',');
ss>>price;
// filtering
if(location==userLocation && test==userTest){
if(price < minPrice){
minPrice = price;
bestHospital = hospital;
}
}
}
if(bestHospital=="")
cout<<"No hospital found in your area\n";
else{
cout<<"\nBest Hospital: "<<bestHospital<<endl;
cout<<"Lowest Price: "<<minPrice<<endl;
}
return 0;
}