ellapt

5.2.ThreeRealNumbProductSign

Dec 14th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using System;
  2. class ThreeRealNumbProductSign
  3. {
  4. static void Main()
  5. {
  6. Console.WriteLine("Please enter three numbers (on separate lines:)");
  7. double numOne = double.Parse(Console.ReadLine());
  8. double numTwo = double.Parse(Console.ReadLine());
  9. double numThree = double.Parse(Console.ReadLine());
  10.  
  11. bool positiveSign = true;
  12. if (numOne > 0.0)
  13. {
  14. if ((numTwo < 0 && numThree > 0) || (numTwo > 0 && numThree < 0))
  15. {
  16. positiveSign = false;
  17. }
  18. }
  19. else if (numOne < 0)
  20. {
  21. positiveSign = (numTwo < 0) ^ (numThree < 0); // false if both are negative or both are positive
  22. }
  23. if (!(numOne == 0 || numTwo == 0 || numThree == 0))
  24. {
  25. Console.WriteLine("Is the product of the three numbers positive? {0}", positiveSign);
  26. }
  27. else
  28. {
  29. System.Console.WriteLine("The product of the three numbers is 0! Try again.");
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment