Answer to Question #342767 in C++ for Lexi

Question #342767

Create a program of temperature conversion (Celsius, farenheit) using array and array structure

1
Expert's answer
2022-05-19T08:56:43-0400
#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);	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS