fork download
  1. //Nathanael Schwartz CS1A Chapter 4, P. 220, #4
  2. //
  3. /*******************************************************************************
  4. *
  5. * DETERMINE LARGER AND SMALLER RECTNGLE AREAS
  6. * ______________________________________________________________________________
  7. * This program asks the user the leangth and width of two different rectangles.
  8. * The program determines which rectangle has a larger area or if the rectangles
  9. * have the same area.
  10. *
  11. * Computations are Based on the Formula:
  12. * area1 = length1 * width1
  13. * area2 = length2 * width2
  14. * ______________________________________________________________________________
  15. * Input
  16. * length1 : the first length entered by the user
  17. * width1 : the first width entered by the user
  18. * length2 : the second length entered by the user
  19. * width2 : the second width entered by the user
  20. *
  21. * Output
  22. * area1 : the first area
  23. * area2 : the second area
  24. *
  25. *******************************************************************************/
  26. #include <iostream>
  27. using namespace std;
  28.  
  29. int main() {
  30. float length1; //INPUT - the first length
  31. float width1; //INPUT - the first width
  32. float length2; //INPUT - the second length
  33. float width2; //INPUT - the sencond width
  34. float area1; //OUTPUT - the first area
  35. float area2; //OUTPUT - the second area
  36.  
  37. // Ask the user for the lengths and widths
  38. cin >> length1;
  39. cout << "The first length is " <<length1 <<"m\n";
  40. cin >> width1;
  41. cout << "The first width is " <<width1 <<"m\n";
  42. cin >> length2;
  43. cout << "The second length is " <<length2 <<"m\n";
  44. cin >> width2;
  45. cout << "The second width is " <<width2 <<"m\n";
  46.  
  47. // Calculate the areas
  48. area1 = width1 * length1;
  49. area2 = width2 * length2;
  50.  
  51. // Determine which area is larger
  52. if (area1 > area2)
  53. {
  54. cout << "The lareger area is the first area at " <<area1 <<"m squared\n";
  55. }
  56. else if (area2 > area1)
  57. {
  58. cout << "The lareger area is the second area at " <<area2;
  59. cout <<"m squared\n";
  60. }
  61. else
  62. {
  63. cout << "The areas are equal at " <<area1 <<"m squared\n";
  64. }
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0.01s 5280KB
stdin
125
170
191
132
stdout
The first length is 125m
The first width is 170m
The second length is 191m
The second width is 132m
The lareger area is the second area at 25212m squared