home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter2 / 2.11 / 2.11.cs next >
Encoding:
Text File  |  2004-08-31  |  2.8 KB  |  71 lines

  1. /* Shorthand notation. */
  2. using System;
  3.  
  4. namespace Chapter2 {
  5.     class Class1 {
  6.         static void Main() {
  7.             string Input;
  8.             int iVariable1, iVariable2, iVariable3, iCharacter;
  9.             // Note: later we'll learn techniques that will allow us 
  10.             // to read partial bits of info, but until then we'll still 
  11.             // want to enter each number with a return statement                                            
  12.             Console.Write("\n Enter two numbers: "); 
  13.             Input = Console.ReadLine();
  14.             iVariable1 = int.Parse(Input);
  15.             Input = Console.ReadLine();
  16.             iVariable2 = int.Parse(Input);
  17.             iVariable3 = iVariable1;
  18.                                    
  19.             Console.WriteLine("\n Enter one symbol: \n addition (+) " 
  20.                 + "\n subtraction (-) \n multiplication (*)"
  21.                 + "\n division (/), or \n remainder (%): ");
  22.             iCharacter = Console.Read();
  23.     
  24.             if (iCharacter == '+') {
  25.                 iVariable1 = iVariable1 + iVariable2;
  26.                 Console.WriteLine("\n Your longhand sum is  " 
  27.                     + iVariable1);  
  28.                 iVariable3 += iVariable2;
  29.                 Console.WriteLine("\n Your shorthand sum is also "
  30.                     + iVariable3);
  31.             } 
  32.     
  33.             if (iCharacter == '-') {
  34.                 iVariable1 = iVariable1 - iVariable2;
  35.                 Console.WriteLine("\n Your longhand difference is  "   
  36.                     + iVariable1);  
  37.                 iVariable3 -= iVariable2;
  38.                 Console.WriteLine("\n Your shorthand difference is  "  
  39.                     + iVariable3);
  40.             }
  41.            
  42.             if (iCharacter == '*') {
  43.                 iVariable1 = iVariable1 * iVariable2;
  44.                 Console.WriteLine("\n Your longhand product is  "
  45.                     + iVariable1);
  46.                 iVariable3 *= iVariable2;
  47.                 Console.WriteLine("\n Your shorthand product is  " 
  48.                     + iVariable3);
  49.             }  
  50.     
  51.             if (iCharacter == '/') {
  52.                 iVariable1 = iVariable1 / iVariable2;
  53.                 Console.WriteLine ("\n Your longhand quotient is  "
  54.                     + iVariable1);  
  55.                 iVariable3 /= iVariable2;
  56.                 Console.WriteLine ("\n Your shorthand quotient is  " 
  57.                     + iVariable3);
  58.             } 
  59.  
  60.             if (iCharacter == '%') {
  61.                 iVariable1 = iVariable1 % iVariable2;
  62.                 Console.WriteLine("\n Your longhand remainder is  " 
  63.                     + iVariable1);  
  64.                 iVariable3 %= iVariable2;
  65.                 Console.WriteLine("\n Your shorthand remainder is  "  
  66.                     + iVariable3);
  67.             }
  68.         } 
  69.     }
  70. }
  71.