Venciity

[Jumpstart C#] Console Demos - Reading Numbers

Jan 22nd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2.  
  3. class ReadingNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("Write a number: ");
  8.         string str = Console.ReadLine();
  9.         int number = Int32.Parse(str);
  10.         //the same as
  11.         //int number = int.Parse(str);
  12.         number++;
  13.         Console.WriteLine("Your number + 1 = {0}", number);
  14.  
  15.  
  16.         Console.Write("a = ");
  17.         string line = Console.ReadLine();
  18.         int a = Int32.Parse(line);
  19.  
  20.         Console.Write("b = ");
  21.         line = Console.ReadLine();
  22.         int b = Int32.Parse(line);
  23.  
  24.         Console.WriteLine("{0} + {1} = {2}",
  25.             a, b, a + b);
  26.         Console.WriteLine("{0} * {1} = {2}",
  27.             a, b, a * b);
  28.  
  29.         Console.Write("f = ");
  30.         line = Console.ReadLine();
  31.         float f = Single.Parse(line);
  32.         Console.WriteLine("{0} * {1} / {2} = {3}",
  33.             a, b, f, a * b / f);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment