Writes a program that repeatedly ask the user to choose one of the choices:
1. Choice 1 : Convert Fahrenheit to Celsius using the formula :
°F = °C x 9/5 + 32
2. Choice 2: Convert Celsius to Fahrenheit using the formula :
°C = (°F - 32) x 5/9
3. Choice 3: Exit the Program
The program should read the user input and then display the result or an error message as appropriate, a sample program run is provided below:
Sample run:
Welcome to the Temperature Converter Application
Please type 1 for Fahrenheit to Celsius conversion
Type 2 for Celsius to Fahrenheit conversion.
Or type -1 to exit the program
1
Please enter your temperature in Fahrenheit
86
Computing...
The temperature in Celsius is 30
Please type 1 for Fahrenheit to Celsius conversion
Type 2 for Celsius to Fahrenheit conversion.
Or type -1 to exit the program
5
That is not an option.
Please type 1 for Fahrenheit to Celsius conversion
Type 2 for Celsius to Fahrenheit conversion.
Or type -1 to exit the program
Look,
We don't do homeworks here. This is not a homework website.
Try some coding and put your code here and we will help you with specific questions you have.
Put the entire program in a while loop. If the user selects the first option, calculate. If the user selects the second option, calculate. if the user selects the third option, put a break statement. If the user selects none of the options, then put a cout statement and the program will continue looping
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <synchapi.h>
double Fahrenheit_to_Celsius()
{
double fahrenheit;
std::cout << "\nPlease enter your temperature in Fahrenheit: ";
std::cin >> fahrenheit;
std::cout << "\nComputing...\n";
Sleep(300);
std::cout << "The temperature in Celsius is: " << (fahrenheit - 32) * 5 / 9;
return 0;
}
double Celsius_to_Fahrenheit()
{
double celsius;
std::cout << "\nPlease enter your temperature in Celsius: ";
std::cin >> celsius;
std::cout << "\nComputing... \n";
Sleep(300);
std::cout << "The temperature in Fahrenheit is: " << celsius * 9 / 5 + 32;
return 0;
}
int main()
{
std::cout << "*** Welcome to the Temperature Converter Application ***\n\n""Type 1 for Fahrenheit to Celsius conversion\n""Type 2 for Celsius to Fahrenheit conversion\n""Type 3 to close the program\n";
int choice;
while (std::cin >> choice)
{
if (choice == 1)
{
Fahrenheit_to_Celsius();
}
if (choice == 2)
{
Celsius_to_Fahrenheit();
}
if (choice == 3)
{
std::cout << "Thank you for using the Temperature Converter Application!\n";
break;
}
if (choice > 3)
{
std::cout << "This is not an option. Please choose from 1 to 3\n";
}
}
std::cin.get();
return 0;
}
I know this is not allowed (or does it apply on for the OP?) I solved this as a part of my part practice. I know it's not the best, but I think it'll do.
Cheers!
(for good coders, if you're not mad at me for solving this guy's issue.. feedback would be great.. as to what I should improve and get used to for better practice in the future)