fork download
  1. //Ava Huntington CS1A Chapter 4 Homework P. 220, #4
  2. //
  3. /*******************************************************************************
  4.  * CALCULATING RECTANGLE AREAS
  5.  * _____________________________________________________________________________
  6.  * This program will take the given length and width of two seperate rectangles
  7.  * and determine which is has a larger area of if they are equal in area.
  8.  *
  9.  * _____________________________________________________________________________
  10.  * INPUT
  11.  * length_1: Given length of rectangle 1
  12.  * length_2: Given length of retangle 2
  13.  * width_1: Given width of rectangle 1
  14.  * width_2: Given width of rectangle 2
  15.  *
  16.  *
  17.  * OUTPUT
  18.  * area_1: Area of rectangle 1 based on given inputs
  19.  * area_2: Area of rectangle 2 based on given inputs
  20.  ******************************************************************************/
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. float length_1; //INPUT: Given length of rectangle 1
  27. float length_2; //INPUT: Given length of rectangle 2
  28. float width_1; //INPUT: Given width of rectangle 1
  29. float width_2; //INPUT: Given width of rectangle 2
  30. float area_1; //OUTPUT: Area of rectangle 1 based on inputs
  31. float area_2; //OUTPUT: Area of rectangle 2 based on inputs
  32.  
  33. //Prompt to get rectangle ones information
  34. cout << "What is the length and width of the first rectangle? Enter the length"
  35. " first then the width seperated by a space please.\n";
  36. cin >> length_1;
  37. cin >> width_1;
  38. area_1 = length_1 * width_1;
  39.  
  40. //Prompt to get rectangle two information
  41. cout << "What is the length and width of the second rectangle? Enter the length"
  42. " first then the width seperated by a space please.\n";
  43. cin >> length_2;
  44. cin >> width_2;
  45. area_2 = length_2 * width_2;
  46.  
  47. //Message if the first rectangles area is larger
  48. if(area_1 > area_2)
  49. {
  50. cout << "Based on the data, rectangle one is larger than rectangle two."
  51. << endl;
  52. }
  53. else if(area_2 > area_1)
  54. {
  55. cout << "Based on the data, rectangle two is larger than rectangle one."
  56. << endl;
  57. }
  58. else if (area_2 == area_1)
  59. cout << "Based on the data, the rectangles have equal areas." << endl;
  60. return 0;
  61. }
Success #stdin #stdout 0.01s 5280KB
stdin
10 8 8 10
stdout
What is the length and width of the first rectangle? Enter the length first then the width seperated by a space please.
What is the length and width of the second rectangle? Enter the length first then the width seperated by a space please.
Based on the data, the rectangles have equal areas.