Advertisement
vlad0

Conditional Statements - Sign Of Product

Dec 4th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2.  
  3.     class SignOfProduct
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.  
  8.  
  9.             decimal enteredNumber;
  10.             bool successParse;
  11.             bool isZero = false;
  12.             byte counter = 0;
  13.  
  14.             for (int i = 0; i < 3; i++)
  15.             {
  16.                 do
  17.                 {
  18.                     Console.Write("Enter the {0} number: ", i+1);
  19.                     successParse = decimal.TryParse(Console.ReadLine(), out enteredNumber);
  20.                    
  21.                 } while (!successParse);
  22.  
  23.                 if (enteredNumber<0)
  24.                 {
  25.                     counter++;
  26.                 }
  27.  
  28.                 else if (enteredNumber==0)
  29.                 {
  30.                     Console.WriteLine("The product is ZERO");
  31.                     isZero = true;
  32.                     break;
  33.                 }
  34.             }
  35.  
  36.             if (!isZero)
  37.             {
  38.  
  39.                 if (counter % 2 == 0)
  40.                 {
  41.                     Console.WriteLine("The sign is +");
  42.                 }
  43.  
  44.                 else
  45.                 {
  46.                     Console.WriteLine("The sign is -");
  47.                 }
  48.             }
  49.  
  50.  
  51.  
  52.  
  53.         }
  54.  
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement