using System; /// Reciprocal demonstrates arithmetic /// assumed input: an integer /// guaranteed output: the number's reciprocal public class Reciprocal { public static void Main() { Console.Write("Please type a nonzero int: "); string input = ""; int n = 1; try { input = Console.ReadLine(); n = Int32.Parse(input); } catch(Exception ex) { // write the internal error, as a `string': Console.WriteLine(ex.ToString()); Console.WriteLine("I'll compute 1/1"); } double answer = 1.0 / n; Console.Write("1.0 / " + input + " is "); Console.WriteLine(answer); Console.ReadLine(); // wait for human to press Enter } }