Newbie here how do i do this

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

2
Please enter your temperature in Celsius
20

Computing...
The temperature in Fahrenheit is 68
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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)
Last edited on
hi Josephreak thank you

I spent 2 days of trying something this is what i came up with, but i am still stuck on the choice parts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <iostream>                        
using namespace std;                       

int main() 

{                               
    float celsius;                         
    float fahrenheit;

cout<<"Choose on of the choices"<<endl;
cout<<"1. Convert Fahrenheit to Celsius"<<endl;
cout<<"2. Convert Celsius to Fahrenheit"<<endl;
cout<<"3. Exit the Program"<<endl;


    cout << "Enter Celsius temperature: "; 
    cin >> celsius;
    fahrenheit = (celsius * 9.0) / 5.0 + 32;
    cout << "Fahrenheit = " << fahrenheit << endl;

    cout << "Enter Fahrenheit  temperature: "; 
    cin >> fahrenheit;
    celsius = (fahrenheit - 32) * 5/9;
    cout << "Celsius = " << celsius << endl;

system("PAUSE");
    return 0;                             
}
closed account (E0p9LyTq)
I spent 2 days of trying something this is what i came up with, but i am still stuck on the choice parts


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>

void fahrenheit_to_celcius();
void celcius_to_fahrenheit();

int main()
{
   bool  quit = false;

   while (quit == false)
   {
      short choice = 0;

      std::cout << "Choose on of the choices\n";
      std::cout << "1. Convert Fahrenheit to Celsius\n";
      std::cout << "2. Convert Celsius to Fahrenheit\n";
      std::cout << "3. Exit the Program\n";
      std::cout << ": ";
      std::cin >> choice;

      switch (choice)
      {
         case 1:
            fahrenheit_to_celcius();
            break;

         case 2:
            celcius_to_fahrenheit();
            break;

         case 3:
            std::cout << "Bye!\n";
            quit = true;
            break;

         default:
            std::cout << "Invalid Input!\n\n";
            break;
      }
   }

   return 0;
}

void fahrenheit_to_celcius()
{
   double fahrenheit_temperature = 0.0;
   double celcius_temperature = 0.0;

   std::cout << "\nEnter Fahrenheit temperature: ";
   std::cin >> fahrenheit_temperature;

   celcius_temperature = (fahrenheit_temperature - 32.0) * 5.0 / 9.0;

   std::cout << "Celsius = " << celcius_temperature << "\n\n";
}

void celcius_to_fahrenheit()
{
   double fahrenheit_temperature = 0.0;
   double celcius_temperature = 0.0;

   std::cout << "\nEnter Celsius temperature: ";
   std::cin >> celcius_temperature;

   fahrenheit_temperature = (celcius_temperature * 9.0) / 5.0 + 32.0;

   std::cout << "Fahrenheit = " << fahrenheit_temperature << "\n\n";
}
Topic archived. No new replies allowed.