forked from rafitc/c_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitConvertor.cpp
More file actions
109 lines (98 loc) · 2.45 KB
/
Copy pathunitConvertor.cpp
File metadata and controls
109 lines (98 loc) · 2.45 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
// Universal Convertor Program Using C++
#include<iostream> //header file
using namespace std;
void calculator(); //Function declaration
void kmTom(); //function declaration
int main(){
string name; //variable to store name
int option; //variable to store user option
cout<<"Hi, Welcome to universal convertor \n";
cout<<"Enter your name : ";
cin>>name; //Input name
cout<<"Hello "<<name<<"\n"; //welcome message
cout<<"choose your option "<<endl; //endl -> used to print in new line
cout<< "1: calculator"<<endl; //each option
cout<< "2: KM to M convertor"<<endl;
cout<< "3: Fahrenheit to Celsius convertor "<<endl;
cin>>option; //user will choose a option
switch(option){
case 1:
calculator(); //calling calculator function
break;
case 2:
kmTom(); //calling Killometer to Meter convertor function
break;
case 3:
//write a function to convert farenheit to celcius
break;
default:
cout<<"Wrong option";
break;
}
}
void calculator(){ //calculator program
int select;
int num_1, num_2, answer;
cout<<"choose your option "<<endl;
cout<< "1: Addition "<<endl;
cout<< "2: subtraction"<<endl;
cout<< "3: Multiplication "<<endl;
cout<< "4: Division "<<endl;
cin>>select;
switch(select){
case 1:
cout<<" Addition"<<endl;
cout<<"Enter First number: " <<endl;
cin>>num_1;
cout<<"Enter second number: "<<endl;
cin>>num_2;
answer = num_1 + num_2;
cout<<"Answer : "<<answer<<endl;
break;
case 2:
cout<<" Subtraction"<<endl;
cout<<"Enter First number: " <<endl;
cin>>num_1;
cout<<"Enter second number: "<<endl;
cin>>num_2;
answer = num_1 - num_2;
cout<<"Answer : "<<answer<<endl;
break;
case 3:
cout<<" Multiplication"<<endl;
cout<<"Enter First number: " <<endl;
cin>>num_1;
cout<<"Enter second number: "<<endl;
cin>>num_2;
answer = num_1 * num_2;
cout<<"Answer : "<<answer<<endl;
break;
case 4:
cout<<" Division"<<endl;
cout<<"Enter First number: " <<endl;
cin>>num_1;
cout<<"Enter second number: "<<endl;
cin>>num_2;
answer = num_1 / num_2;
cout<<"Answer : "<<answer<<endl;
break;
default:
break;
}
}
void kmTom(){ //Kilometre to Meter fucntion
float km;
float meter;
cout<<"\n Enter value in Kilometre: ";
cin>>km;
meter = km * 1000;
cout<<km<<" KM is equal to "<<meter << " Meter";
}
void mtocm(){
float m;
float cm;
cout<<"\n Enter value in Meter: ";
cin>>m;
cm = m * 100;
cout<<m<<" M is equal to "<<cm << " CM";
}