SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Barbara Dolye
Chapter:
Data Types And Expressions
Exercise:
Programming Exercises
Question:3 | ISBN:9781285096261 | Edition: 4

Question

Write a program that converts a temperature given in Celsius to Fahrenheit.
Test the program by performing a compile-time initialization of 32 for the
original Celsius value. Display the original temperature and the formatted
converted value. Go into your source code and change the initialization value
to 0. Rerun the application. Select additional test values and rerun the
application.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

 Solution:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CelsiusToFahrenheit
{
    // Create a class named CelsiusToFahrenheit
    class CelsiusToFahrenheit
    {
        // Create a main method to run the program
        static void Main(string[] args)
        {
            
            // Declare a double variable named celsius to store the celsius value.
            double celsius = 32;
            // Declare a double variable named fahrenheit to store the fahrenheit value.
            double fahrenheit;

            //logical formula for convertion from celsius to fahrenheit
            //fahrenheit=((celsius*9)/5)+32;


            fahrenheit = ((celsius * 9)/ 5) + 32; //convertion from celsius to fahrenheit
            //display celsius value up to two decimal places
            Console.WriteLine("Delared Celsius Value : " + "{0:f2}", +celsius);
            //display fahrenheit value up to two decimal places
            Console.WriteLine("Convertred Fahrenheit Value : " + "{0:f2}", +fahrenheit);
 
        }
    }
}

 

Output 1:

Delared Celsius Value : 32.00
Convertred Fahrenheit Value : 89.60

Output 2:

Delared Celsius Value : 0.00
Convertred Fahrenheit Value : 32.00

 

0 0

Discussions

Post the discussion to improve the above solution.