Programming Challenge Chapter 3 – Q #6 How Many Widgets? – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #6 How Many Widgets? – Tony Gaddis – Starting Out With C++


Problem: -

The Yukon Widget Company manufactures widgets that weigh 9.2 pounds each. Write a program that calculates how many widgets are stacked on a pallet, based on the total weight of the pallet. The program should ask the user how much the pallet weighs by itself and with the widgets stacked on it. It should then calculate and display the number of widgets stacked on the pallet.

Solution: -

#include <iostream>

using namespace std;

int main()

{

      const float  WIDGETS = 9.2;

 

      float pallat_weight, pallat_widgets_itself, total_widgets = 0.0;

      float widgets;

 

      cout << "Enter Pallat Wieght By its Self: ";

      cin >> pallat_widgets_itself;

      cout << "Enter Pallat Weight With Widgets: ";

      cin >> pallat_weight;

 

      widgets = pallat_weight - pallat_widgets_itself;

      total_widgets = widgets / WIDGETS;

 

      cout << "Pallat Weight =         " << widgets << endl;

      cout << "Number of Widgets =     " << total_widgets << endl;

 

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.


Explanation of this Solution

  1. Declare float constant and initialize given values.
  2. Declare three float variables.
  3. Declare a float variables for calculation.
  4. Take input from the user by using cin.
  5. Take input from the user by using cin.
  6. Calculate widgets and total widgets.
  7.  In last, display output on the screen.
  8. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File




Thanks!  

Post a Comment

0 Comments