fork download
  1. //Max Kichuk CS1A Chapter 4, P. 220, #4
  2.  
  3. /**********************************************************************
  4.  *
  5.  * DIFFERENTIATE RECTANGLE AREA
  6.  * ____________________________________________________________________
  7.  * This program computes the area of two rectangles. It then compares
  8.  * the areas and tells you which one is greater or if they are equal
  9.  * to each other.
  10.  *
  11.  * Computation is based on the formula:
  12.  * area = length * width
  13.  * ____________________________________________________________________
  14.  * INPUT
  15.  * length1 : Length of rectangle 1
  16.  * width1 : Width of rectangle 1
  17.  * length2 : Length of rectangle 2
  18.  * width2 : Width of rectangle 2
  19.  *
  20.  * OUTPUT
  21.  * area1 : Area of rectangle 1
  22.  * area2 : Area of rectangle 2
  23.  *
  24.  **********************************************************************/
  25. #include <iostream>
  26. #include <iomanip>
  27. using namespace std;
  28.  
  29. int main() {
  30. float length1; // INPUT: Length of rectangle 1
  31. float width1; // INPUT: Width of rectangle 1
  32. float area1; // OUTPUT: Area of rectangle 1
  33. float length2; // INPUT: Length of rectangle 2
  34. float width2; // INPUT: Width of rectangle 2
  35. float area2; // OUTPUT: Area of rectangle 2
  36.  
  37. // Ask the user for the first rectangle's information
  38. cout << "Enter the length of the first rectangle: " << endl;
  39. cin >> length1;
  40. cout << "Enter the width of the first rectangle: " << endl;
  41. cin >> width1;
  42.  
  43. // Calculate the area of the first rectangle and output it.
  44. area1 = length1 * width1;
  45. cout << "The area of rectangle one is " << area1 << " units^2." << endl;
  46. cout << endl;
  47.  
  48. cout << "Enter the length of the second rectangle: " << endl;
  49. cin >> length2;
  50. cout << "Enter the width of the second rectangle: " << endl;
  51. cin >> width2;
  52. area2 = length2 * width2;
  53. cout << "The area of rectangle two is " << area2 << " units^2." << endl;
  54. cout << endl;
  55.  
  56. // Differtiate between rectangles
  57. if (area1 > area2){
  58. cout << "The area of the first rectangle (";
  59. cout << area1 << " units^2) ";
  60. cout << "is greater than the second rectangle (";
  61. cout << area2 << " units^2). ";
  62. }
  63. else if (area2 > area1){
  64. cout << "The area of the second rectangle (";
  65. cout << area2 << " units^2) ";
  66. cout << "is greater than the first rectangle (";
  67. cout << area1 << " units^2). ";
  68. }
  69. else{
  70. cout << "The area of the first rectangle (";
  71. cout << area1 << " units^2) ";
  72. cout << "is equal to the second rectangle (";
  73. cout << area2 << " units^2). ";
  74. }
  75. return 0;
  76. }
Success #stdin #stdout 0s 5360KB
stdin
Standard input is empty
stdout
Enter the length of the first rectangle: 
Enter the width of the first rectangle: 
The area of rectangle one is 0 units^2.

Enter the length of the second rectangle: 
Enter the width of the second rectangle: 
The area of rectangle two is 2.3906e-12 units^2.

The area of the second rectangle (2.3906e-12 units^2) is greater than the first rectangle (0 units^2).