Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Christian Ballard
- //COSC 1330 - 003
- //This program should convert temperatures between Celsius and Fahrenheit.
- #include <iostream>
- #include <iomanip>
- using namespace std;
- //PROTOTYPES!!!!!!
- char getTempType(char);
- double convertToCelsius(double &, double &);
- double convertToFahrenheit(double &, double &);
- int main()
- {
- char answer = ' '; //Variables.
- double celsius = 0.0;
- double fahrenheit = 0.0;
- double convertedCelsius = 0.0;
- double convertedFahrenheit = 0.0;
- char loopAnswer = ' ';
- cout << fixed << setprecision(1);
- do //AND THE LOOPIES BEGIN!!!
- {
- system("cls"); //I put this here to keep the loop from displaying previous output.
- answer = getTempType(answer); //Assigning answer to what the user inputs in the function.
- system("cls"); //Figured it would be nice to clear the screen here.
- switch (answer) //Figuring out what exactly we want to do determined by user input.
- {
- case '1':
- convertToCelsius(celsius, convertedCelsius);
- cout << "The conversion from " << celsius << ("\xF8") << " Celsius is " << convertedCelsius << ("\xF8") << " Fahrenheit." << endl << endl;
- break;
- case '2':
- convertToFahrenheit(fahrenheit, convertedFahrenheit);
- cout << "The conversion from " << fahrenheit << ("\xF8") << " Fahrenheit is " << convertedFahrenheit << ("\xF8") << " Celsius." << endl << endl;
- break;
- default:
- cout << "Invalid input, please enter either 1 or 2." << endl;
- break;
- }
- cout << "Would you like to convert another temperature? (Y/N)" << endl; //Update read
- cin >> loopAnswer;
- } while (loopAnswer == 'Y' || loopAnswer == 'y');
- if (loopAnswer == 'n' || loopAnswer == 'N')
- {
- system("cls");
- cout << "See ya later!" << endl;
- }
- system("pause");
- return 0;
- }
- char getTempType(char funAnswer)//funAnswer is my second variable for answer. It stands for Function Answer.
- {
- cout << "To convert from Celsius to Fahrenheit please press 1." << endl;
- cout << "To convert from Fahrenheit to Celsius please press 2." << endl;
- cin >> funAnswer;
- return funAnswer;
- }
- double convertToCelsius(double &funCelsius, double &funConvertedCelsius)
- {
- cout << "Please enter the degrees Celsius" << endl;
- cin >> funCelsius;
- funConvertedCelsius = (funCelsius * 1.8) + 32;
- return funCelsius, funConvertedCelsius;
- }
- double convertToFahrenheit(double &funFahrenheit, double &funConvertedFahrenheit)
- {
- cout << "Please enter the degrees Fahrenheit" << endl;
- cin >> funFahrenheit;
- funConvertedFahrenheit = (funFahrenheit - 32) / 1.8;
- return funFahrenheit, funConvertedFahrenheit;
- }
Advertisement
Add Comment
Please, Sign In to add comment