8000 added file : temperature calculator · Josh-D18/C-CPP-Programming@ac17d78 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac17d78

Browse files
author
Easter-Maxwell-01
committed
added file : temperature calculator
1 parent 1bed3b8 commit ac17d78

File tree

1 file changed

+243
-0
lines changed

1 file changed

+243
-0
lines changed
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
/*
2+
project status : 1
3+
Date : Oct 11, 2022
4+
Author : Easter Maxwell
5+
*/
6+
7+
/*'Error --1' is just a random error message*/
8+
9+
//control number output
10+
#include <iomanip>
11+
12+
//for system operations
13+
#include <windows.h>
14+
15+
#include <iostream>
16+
17+
using namespace std;
18+
19+
void standard_output()
20+
{
21+
int fahr;
22+
int order;
23+
int celsius;
24+
int lower_value;
25+
int upper_value;
26+
27+
cout << "\n";
28+
cout << "[+]Enter Order value : ";
29+
cin >> order;
30+
31+
cout << "\n";
32+
cout << "[+]Enter Lower Value : ";
33+
cin >> lower_value;
34+
35+
cout << "\n";
36+
cout << "[+]Enter Upper Value : ";
37+
cin >> upper_value;
38+
39+
/*enables 'fahr' to start printing from the lowest value*/
40+
fahr = lower_value;
41+
42+
cout << "\n";
43+
cout << "\t\t\t\t\t ";
44+
cout << "--- Temperature ---" << endl;
45+
46+
cout << "\n";
47+
cout << "\t\t\t\t\t "
48+
<< "+----------------------------+"
49+
<< "\n"
50+
<< "\t\t\t\t\t "
51+
<< "| Fahrenheit Celsius |"
52+
<< "\n"
53+
<< "\t\t\t\t\t "
54+
<< "+--------------|-------------+";
55+
56+
while (fahr <= upper_value)
57+
{
58+
/*Formula (Fahrenheit to Celsius)*/
59+
celsius = 5 * (fahr - 32) / 9;
60+
61+
cout << "\n";
62+
cout << "\t\t\t\t\t ";
63+
64+
cout << "| " << fahr << "\t\t " << celsius << " |";
65+
66+
cout << "\n";
67+
cout << "\t\t\t\t\t ";
68+
cout << "+--------------|-------------+";
69+
70+
/*increments fahrenheit by the 'order' value*/
71+
fahr = fahr + order;
72+
}
73+
74+
}
75+
76+
void user_specific_output()
77+
{
78+
string option;
79+
float fahr_input;
80+
float fahr_value;
81+
float celsius_input;
82+
float celsius_value;
83+
84+
cout << "\t\t\t\t\t "
85+
<< "--- Available Options ---" << endl;
86+
87+
cout << "\t\t\t "
88+
<< "\n"
89+
<< "\t\t\t "
90+
<< "+-----------------------------------------------------------+"
91+
<< "\t\t\t "
92+
<< "\n"
93+
<< "\t\t\t "
94+
<< "| Press F to convert temperature from Fahrenheit to celsius |"
95+
<< "\t\t\t "
96+
<< "\n"
97+
<< "\t\t\t "
98+
<< "| --------------------------------------------------------- |"
99+
<< "\t\t\t "
100+
<< "\n"
101+
<< "\t\t\t "
102+
<< "| Press C to convert temperature from Celsius to Fahrenheit |"
103+
<< "\t\t\t "
104+
<< "\n"
105+
<< "\t\t\t "
106+
<< "+-----------------------------------------------------------+";
107+
108+
cout << "\n\n";
109+
cout << "[:]Enter Option : ";
110+
cin >> option;
111+
112+
if (option == "C" || option == "c")
113+
{
114+
cout << "\n";
115+
cout << "[+]Enter Temperature in Celsius : ";
116+
cin >> celsius_input;
117+
118+
/*Formula (Celsius to Fahrenheit)*/
119+
fahr_value = (9.0 / 5.0) * celsius_input + 32;
120+
121+
cout << "\n";
122+
cout << "\t\t\t\t\t ";
123+
cout << "--- Result ---" << endl;
124+
125+
cout << "\n";
126+
cout << "\t\t\t\t\t "
127+
<< "+----------------------------+"
128+
<< "\n"
129+
<< "\t\t\t\t\t "
130+
<< "| Celsius Fahrenheit |"
131+
<< "\n"
132+
<< "\t\t\t\t\t "
133+
<< "+--------------|-------------+";
134+
135+
cout << "\n";
136+
cout << "\t\t\t\t\t ";
137+
cout << "| " << celsius_input << "\t | " << setprecision(3) << fahr_value << "\t |";
138+
139+
cout << "\n";
140+
cout << "\t\t\t\t\t ";
141+
cout << "+----------------------------+";
142+
143+
}
144+
145+
else if (option == "F" || option == "f")
146+
{
147+
cout << "\n";
148+
cout << "[+]Enter Temperature in Fahrenheit : ";
149+
cin >> fahr_input;
150+
151+
/*Formula (Fahrenheit to Celsius)*/
152+
celsius_value = 5 * (fahr_input - 32) / 9;
153+
154+
cout << "\n";
155+
cout << "\t\t\t\t\t ";
156+
cout << "--- Result ---" << endl;
157+
158+
cout << "\n";
159+
cout << "\t\t\t\t\t "
160+
<< "+----------------------------+"
161+
<< "\n"
162+
<< "\t\t\t\t\t "
163+
<< "| Fahrenheit Celsius |"
164+
<< "\n"
165+
<< "\t\t\t\t\t "
166+
<< "+--------------|-------------+";
167+
168+
cout << "\n";
169+
cout << "\t\t\t\t\t ";
170+
cout << "| " << fahr_input << "\t | " << setprecision(3) << celsius_value << "\t |";
171+
172+
cout << "\n";
173+
cout << "\t\t\t\t\t ";
174+
cout << "+----------------------------+";
175+
}
176+
177+
else
178+
{
179+
Sleep(500);
180+
cout << "\n[:]#Msg : Error --1" << endl;
181+
cout << "[:}Fault : Invalid option Input!" << endl;
182+
}
183+
184+
}
185+
186+
int main()
187+
{
188+
string user_input;
189+
190+
cout << "\t\t\t\t\t ";
191+
cout << "--- TEMPERATURE CALCULATOR ---";
192+
cout << "\n\n";
193+
194+
cout << "\t\t\t\t\t"
195+
<< "+------------------------------------+"
196+
<< "\t\t\t\t\t"
197+
<< "\n"
198+
<< "\t\t\t\t\t"
199+
<< "| Press 0 to display standard input |"
200+
<< "\t\t\t\t\t"
201+
<< "\n"
202+
<< "\t\t\t\t\t"
203+
<< "| ---------------------------------- |"
204+
<< "\t\t\t\t\t"
205+
<< "\n"
206+
<< "\t\t\t\t\t"
207+
<< "| Press X to display specific output |"
208+
<< "\t\t\t\t\t"
209+
<< "\n"
210+
<< "\t\t\t\t\t"
211+
<< "+------------------------------------+"
212+
<< "\n\n";
213+
214+
cout << "[:]Enter option : ";
215+
cin >> user_input;
216+
217+
if (user_input == "0" || user_input == "o" || user_input == "O" C5B5 )
218+
{
219+
Sleep(500);
220+
221+
/*display this function*/
222+
standard_output();
223+
}
224+
225+
else if (user_input == "X" || user_input == "x" || user_input == "*")
226+
{
227+
Sleep(500);
228+
229+
/*display this function*/
230+
user_specific_output();
231+
}
232+
233+
else
234+
{
235+
Sleep(500);
236+
cout << "\n[:]#Msg : Error --1" << endl;
237+
cout << "[:}Fault : Invalid option Input!" << endl;
238+
}
239+
240+
return -1;
241+
242+
}
243+

0 commit comments

Comments
 (0)
0