fork download
  1. //Sam Partovi CS1A Chapter 3, P. 144, #6
  2. //
  3. /*******************************************************************************
  4. *
  5. * CALCULATE WIDGET COUNT
  6. * ____________________________________________________________
  7. * This program calculates the number of widgets stacked on a pallet with a
  8. * given widget weight, as well as the weight of the pallet with and without
  9. * carrying the widgets.
  10. *
  11. * The calculation is based on the following formula:
  12. * widgetCount = ( loadedPalletWeight - rawPalletWeight ) / widgetWeight
  13. * ____________________________________________________________
  14. *INPUT
  15. * widgetWeight : Weight (lbs) of each widget
  16. * rawPalletWeight : Weight (lbs) of the unloaded pallet
  17. * loadedPalletWeight : Weight (lbs) of the pallet carrying widgets
  18. *OUTPUT
  19. * widgetCount : Number of widgets held on the pallet
  20. *
  21. ******************************************************************************/
  22.  
  23. #include <iostream>
  24. #include <string>
  25.  
  26. using namespace std;
  27.  
  28. int main() {
  29.  
  30. float rawPalletWeight; //INPUT - Weight (lbs) of the unloaded pallet
  31. float loadedPalletWeight; //INPUT - Weight (lbs) of the pallet carrying widgets
  32. int widgetCount; //Number of widgets held on the pallet
  33.  
  34. //Initialize program variable
  35. const float widgetWeight = 9.2; //INPUT - Weight (lbs) of each widget
  36.  
  37. //Prompt user for pallet weight variables
  38. cout << "Enter the raw pallet weight: ";
  39. cin >> rawPalletWeight;
  40. cout << "\nEnter the loaded pallet weight: ";
  41. cin >> loadedPalletWeight;
  42.  
  43. //Perform calulcation of widgetCount
  44. widgetCount = (loadedPalletWeight - rawPalletWeight) / widgetWeight;
  45.  
  46. //Display number of widgets
  47. cout << "\nAt " << widgetWeight << " pounds per widget, the pallet is carrying "
  48. << widgetCount << " widgets.\n";
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0s 5280KB
stdin
10
470
stdout
Enter the raw pallet weight: 
Enter the loaded pallet weight: 
At 9.2 pounds per widget, the pallet is carrying 50 widgets.