-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMinMaxFahrenheitCelsius.cpp
More file actions
46 lines (34 loc) · 1.14 KB
/
MinMaxFahrenheitCelsius.cpp
File metadata and controls
46 lines (34 loc) · 1.14 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
/*
Conversion Fahrenheit To Celsius
Take the following as input:
1. Minimum Fahrenheit Value.
2. Maximum Fahrenheit Value.
3. Step.
Print as output the Celsius Conversion. Use the formula C = (5/9)(F-32).
First number in every output line is Fahrenheit, second number is Celsius.
The two numbers are seperated by a tab.
*/
#include<iostream>
using namespace std;
int main()
{
int minF, maxF, step, c;
cout<<"Enter minimum Fahrenheit value : ";
cin>>minF;
cout<<endl<<"Enter maximum Fahrenheit value : ";
cin>>maxF;
cout<<endl<<"Enter step value ( >0 ) : ";
cin>>step;
if(step!=0)
{
for(int i=minF; i<=maxF; i=i+step)
{
c=((i-32)*5)/9; //since c is int type 5/9 will always give 0. The formula is still the same but
//now precedence is changed as (i-32)*5 will be evaluated first and then divide by 9.
cout<<i<<"\t"<<c<<endl;
}
}
else
cout<<endl<<"Step value should be greater than 0 !!!";
return 0;
}