Create a program of temperature conversion (Celsius, farenheit) using array and array structure
#include <iostream>
using namespace std;
struct Celsius
{
float value;
Celsius(){}
};
struct Farenheit
{
float value;
Farenheit() {}
};
void Menu()
{
cout << "Select some of the following:\n"
<< "1 - Convert Celsius to Farenheit\n"
<< "2 - Convert Farenheit to Celsius\n"
<< "0 - Exit program\n";
cout << "Select choice: ";
}
int main()Â
{
char ch;
do
{
Menu();
cin >> ch;
if (ch == '0')break;
int n;
cout << "Please, enter a number of values: ";
cin >> n;
Celsius* pc = new Celsius[n];
Farenheit* pf = new Farenheit[n];
switch (ch)
{
case '1':
{
cout << "Please, enter values in Celsius: ";
for (int i = 0; i < n; i++)
{
cin >> pc[i].value;
pf[i].value = (9.0 / 5.0)*pc[i].value + 32;
}
cout << "Resulting values in Farenheit: ";
for (int i = 0; i < n; i++)
{
cout << pf[i].value << " ";
}
cout << endl;
break;
}
case '2':
{
cout << "Please, enter values in Farenheit: ";
for (int i = 0; i < n; i++)
{
cin >> pf[i].value;
pc[i].value = (pf[i].value-32.0)*5.0/9.0;
}
cout << "Resulting values in Celsius: ";
for (int i = 0; i < n; i++)
{
cout << pc[i].value << " ";
}
cout << endl;
break;
}
}
delete[]pc;
delete[]pf;
} while (true);
}
Comments
Leave a comment