Advertisement
allerost

Celsius to Fahrenheit converter

Aug 27th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.        
  12.        
  13.         //Metod: Celsius to Fahrenheit, konverterar C till F
  14.         static int CelsiusToFahrenheit(int celsius)
  15.         {
  16.  
  17.        
  18.            
  19.             //Vilken uträckning datorn ska göra för att få fram vad celsius blir om man konverterar den till Fahrenheit.
  20.             int fahrenheit = ((celsius * 9) / 5) + 32;
  21.             return fahrenheit;
  22.         }        
  23.        
  24.         //Startar programmet
  25.         static void Main(string[] args)
  26.         {
  27.  
  28.             //Console.WindowHeigh ändrar höjden på CMD rutan som öppnas.
  29.             //Console.WindowWidth ändrar tjockleken på CMD rutan som öppnas.
  30.  
  31.            
  32.            
  33.             Console.WindowHeight = 10;
  34.             Console.WindowWidth = 60;
  35.             //Anger vilken färg som texten i CMD ska vara.
  36.             Console.ForegroundColor = ConsoleColor.Red;
  37.             //Ber dig att ange celsius som sedan ska konverteras Fahrenheit.
  38.             Console.WriteLine("--Skriv in grader i Celsius: ");
  39.             int celsius = Convert.ToInt32(Console.ReadLine());
  40.  
  41.             //konverterar celsius till Fahrenheit
  42.             int fahrentheit = CelsiusToFahrenheit(celsius);
  43.             //Anger vilken färg som texten i CMD ska vara.
  44.             Console.ForegroundColor = ConsoleColor.Magenta;
  45.             Console.WriteLine(celsius + " grader Celsius blir " + fahrentheit + "grader i Fahrenheit.--");
  46.             Console.ReadKey();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement