fork download
  1. //Natalie Zarate Chapter 5, P. 220, #4
  2.  
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE AND COMPARE
  6.  * _____________________________________________________________________________
  7.  * This program accepts as input the length and width of two rectangles then
  8.  * computes the area of the rectangles which are then compared to determine
  9.  * whether their areas are equal to eachother or if one's area is greather than
  10.  * the area of the other.
  11.  * depending on how many seconds the user inputs.
  12.  * _____________________________________________________________________________
  13.  * INPUT
  14.  * width_1 : width of the first rectangle
  15.  * length_1 : length of the first rectangle
  16.  * width_2 : width of the second rectangle
  17.  * length_2 : length of the second rectangle
  18.  *
  19.  * OUTPUT
  20.  * area_1 : area of the first rectangle
  21.  * area_2 : area of the second rectangle
  22.  * Comparision of both areas
  23.  *
  24.  ******************************************************************************/
  25. #include <iostream>
  26. #include <iomanip>
  27. using namespace std;
  28.  
  29. int main()
  30. {
  31. float width_1; // INPUT - width of the first rectangle
  32. float width_2; // INPUT - width of the second rectangle
  33. float length_1; // INPUT - length of the first rectangle
  34. float length_2; // INPUT - length of the second rectangle
  35. float area_1; // OUTPUT - area of the first rectangle
  36. float area_2; // OUTPUT - area of the second rectangle
  37.  
  38. // Prompt user for 1st rectangle's width and length
  39. cout << "Enter width of the first rectangle:" << endl;
  40. cin >> width_1;
  41. cout << "Enter length of the first rectangle:" << endl;
  42. cin >> length_1;
  43.  
  44. // Prompt user for the 2nd rectangle's width and length
  45. cout << "Enter width of the second rectangle:" << endl;
  46. cin >> width_2;
  47. cout << "Enter length of the second rectangle:" << endl;
  48. cin >> length_2;
  49.  
  50. // Calculate area of the rectangles
  51. area_1 = width_1 * length_1;
  52. area_2 = width_2 * length_2;
  53.  
  54. // Display calculations
  55. cout << endl;
  56. cout << "The area of the first rectangle is " << area_1 << "." << endl;
  57. cout << "The area of the second rectangle is " << area_2 << "." << endl;
  58.  
  59. // Display comparision
  60. if (area_1 > area_2)
  61. {
  62. cout << "The area of the first rectangle is greater than the second";
  63. cout << " rectangle's area." << endl;
  64. }
  65. if (area_2 > area_1)
  66. {
  67. cout << "The area of the second rectangle is greater than the first";
  68. cout << " rectangle's area." << endl;
  69. }
  70. if (area_1 == area_2)
  71. cout << "The area of the rectangles are equal.";
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5280KB
stdin
6
3
9
2
stdout
Enter width of the first rectangle:
Enter length of the first rectangle:
Enter width of the second rectangle:
Enter length of the second rectangle:

The area of the first rectangle is 18.
The area of the second rectangle is 18.
The area of the rectangles are equal.