Computer Science, asked by syedhassankhan1, 7 months ago

write a program that has main() call a user-defined function that take a celsius temperature value as an argument and then returns the equivalent Fahrenheit value.the program should request the Celsius value as input from the user and display the result ,as shown in the following code. please enter a Celsius value : 20 20 degrees Celsius is 68 degrees Fahrenheit Note : for reference , here is the formula for making the conversion : Fahrenheit =1.8*degrees Celsius+32.0

Answers

Answered by archana1501singh
2

Explanation:

This problem is simple and just demonstration C++ Functions. Below mention code is compiled in Visual Studio 2015 and output snap is attached.. If any problem you feel and want explanation feel free to contact.

Code:

/**************************************************|

/*************C++ Programs And Projects************|

***************************************************/

#include<iostream>

using namespace std;

//function prototype

int celsiusToFahrenheitConverter(int);

void main() {

int celsius;

cout << "Please enter a Celsius value == ";

cin >> celsius;

cout << celsius << " degrees Celsius is " << celsiusToFahrenheitConverter(celsius) << " degrees Fahrenheit" << endl;

}

int celsiusToFahrenheitConverter(int celsius) {

int Fahrenheit = 1.8 * celsius + 32.0;

return Fahrenheit;

}

Answered by Shivu516
0

This program is in Java and it can convert both Celcius to Fahrenheit and vice-versa. I have also added all the possible outputs ^_^

import java.util.Scanner;

public class CelciusToFahrenheit{

  public static void main (String [] args){

      Scanner sc = new Scanner(System.in);

      System.out.println("Press 0 for Celcius to Fahrenheit and 1 for Vice-Versa");

      double choice = sc.nextDouble();

      if (choice == 0){

          System.out.print("Enter the temperature in Celcius: ");

          double tempC = sc.nextDouble();

          double tempF = (tempC*1.8) + 32;

          System.out.println("The temperature in Fahrenheit: " + tempF + "°F");}

      if (choice == 1){

          System.out.print("Enter the temperature in Fahrenheit: ");

          double tempF = sc.nextDouble();

          double tempC = (tempF - 32)/1.8;

          System.out.println("The temperature in Celcius: " + tempC + "°C");}

      if (choice != 0 && choice != 1)

      System.out.println("Enter only 1 or 2 :(");

  }

}

Output:

(i)

Press 1 for Celcius to Fahrenheit and 2 for Vice-Versa

123

Enter only 1 or 2 :(

(ii)

Press 1 for Celcius to Fahrenheit and 2 for Vice-Versa

1

Enter the temperature in Celcius: 37

The temperature in Fahrenheit: 98.60000000000001°F

(iii)

Press 1 for Celcius to Fahrenheit and 2 for Vice-Versa

2

Enter the temperature in Fahrenheit: 98.6

The temperature in Celcius: 36.99999999999999°C

Similar questions