fork download
  1. //Matthew Santos CS1A Ch. 4, Pg. 220, #4
  2. /***********************************************
  3.  *
  4.  * COMPARE RECTANGLE AREAS
  5.  * _____________________________________________
  6.  * DESCRIPTION
  7.  * Compares the areas of two rectangles and
  8.  * compares them to see which is bigger.
  9.  * _____________________________________________
  10.  * INPUT
  11.  * length1 : length of first rectangle
  12.  * width1 : width of first rectangle
  13.  * length2 : length of second rectangle
  14.  * width2 : width of second rectangle
  15.  *
  16.  * OUTPUT
  17.  * Displays which area is greater
  18.  ***********************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main() {
  23.  
  24. //Initialize variables
  25. float length1;
  26. float width1;
  27. float length2;
  28. float width2;
  29. float area1;
  30. float area2;
  31.  
  32. //Acquire dimensions
  33. cin >> length1;
  34. cin >> width1;
  35. cin >> length2;
  36. cin >> width2;
  37.  
  38. //Determine the areas
  39. area1 = length1 * width1;
  40. area2 = length2 * width2;
  41.  
  42. //Determine which is greater
  43. if (area1 > area2)
  44. {
  45. cout << "The area of the first rectangle is greater than the area of the second rectanlge." << endl;
  46. }
  47. else
  48. if (area1 < area2)
  49. {
  50. cout << "The area of the second rectangle is greater than the area of the first rectanlge." << endl;
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5288KB
stdin
4
5
5
6
stdout
The area of the second rectangle is greater than the area of the first rectanlge.