fork download
  1. //Sam Partovi CS1A Chapter 4, P. 220, #1
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COMPARE NUMBER SIZE
  6.  * ____________________________________________________________
  7.  * This program receives two numbers and evaluates them to determine which
  8.  * number is the smallest and which number is the largest.
  9.  * ____________________________________________________________
  10.  * INPUT
  11.  *
  12.  * initialNumber : The first number to be compared
  13.  * secondNumber : The second number to be compared
  14.  *
  15.  ******************************************************************************/
  16. #include <iostream>
  17. #include <iomanip>
  18. using namespace std;
  19. int main ()
  20. {
  21.  
  22. double initialNumber;
  23. double secondNumber;
  24.  
  25. //Prompt user for initialNumber and secondNumber
  26. cout << "Enter a number: ";
  27. cin >> initialNumber;
  28. cout << "\nEnter another number: ";
  29. cin >> secondNumber;
  30. cout << right << "\n-----------------------\n";
  31.  
  32. //Evaluate minimum and maximum number
  33. if (initialNumber > secondNumber) {
  34. cout << "The larger number is " << initialNumber <<
  35. " and the smaller number is " << secondNumber;
  36. }
  37. else if (secondNumber > initialNumber) {
  38. cout << "The larger number is " << secondNumber <<
  39. " and the smaller number is " << initialNumber;
  40. }
  41. else if (initialNumber == secondNumber) {
  42. cout << initialNumber << " is equal to " << secondNumber << endl;
  43. }
  44. else {
  45. cout << "Error in evaluating number size.\n";
  46. }
  47. return 0;
  48. }
  49.  
  50.  
Success #stdin #stdout 0.01s 5276KB
stdin
2.34E-54
1.25E-54
stdout
Enter a number: 
Enter another number: 
-----------------------
The larger number is 2.34e-54 and the smaller number is 1.25e-54