-
Notifications
You must be signed in to change notification settings - Fork 1
/
b1oops.cpp
87 lines (87 loc) · 1.87 KB
/
b1oops.cpp
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
#include <iostream>
#include <cstring>
using namespace std;
class Error{
int eage;;
float eincome;
string estr;
public:
Error(int a){
eage=a;
}
Error(float i){
eincome=i;
}
Error(string s){
estr=s;
}
void err_age(){
cout<<"Invalid age : "<<eage<<endl;
}
void err_income(){
cout<<"Invalid income : "<<eincome<<endl;
}
void err_str(){
cout<<"Invalid Vallue: "<<estr<<endl;
}
};
int main(){
int age;
float income;
string city,vehicle;
try{
cout<<"Enter Age (between 18 to 55):\n";
cin>>age;
if(age<18||age>55){
throw Error(age);
}
else{
cout<<"Age is : "<<age<<endl;
}
}
catch(Error e){
e.err_age();
}
try{
cout<<"Enter monthly income in INR (between 50000 to 100000) :\n";
cin>>income;
if(income<50000||income>100000){
throw Error(income);
}
else{
cout<<"Monthly income in INR is :"<<income<<endl;
}
}
catch(Error e){
e.err_income();
}
try{
cout<<"Enter City (pune or mumbai or bangalore or chennai):\n";
cin>>city;
if(city == "pune" || city == "mumbai" || city == "bangalore" || city == "chennai"){
cout<<"City is :"<<city<<endl;
}
else{
throw Error(city);
}
}
catch(Error e){
cout<<"\nCity not allowed; ";
e.err_str();
}
try{
cout<<"Enter type of vehicle (2-wheeler/4-wheeler):\n";
cin>>vehicle;
if(vehicle == "2-wheeler"||vehicle == "4-wheeler"){
cout<<"Vehicle is : "<<vehicle<<endl;
}
else{
throw Error(vehicle);
}
}
catch(Error e){
cout<<"\nInvalid Vehicle;";
e.err_str();
}
return 0;
}