Programming Challenge Chapter 3 – Q #7 How Many Calories? – Tony Gaddis – Starting Out With C++
Problem: -
Solution: -
#include <iostream>
using namespace std;
int main()
{
const float bag_of_cookies = 40.0,
serving = 10.0,
serving_per_bag = 300.0;
float cookies_per_serving = bag_of_cookies / serving_per_bag;
float cookies_eat, serving_eat, consumed_eat;
cout << "How Many Cookies
Eaten: ";
cin >> cookies_eat;
serving_eat = cookies_eat / cookies_per_serving;
consumed_eat = serving_eat * serving_per_bag;
cout << "Cookies Eaten =
" << cookies_eat << endl;
cout << "Calories Consumed
= " << consumed_eat << endl;
return 0;
}
This is the solution of this question
OUTPUT OF THIS QUESTION
Input is highlighted with yellow color.
Explanation of this Solution
- Declare three float constants and initialize given values.
- Declare a float variable for per serving calculation.
- Declare three float variables for calculation and input.
- Take input from the user by using cin.
- Calculate the values.
- In last, display output on the screen.
- Return 0 to the main function.
Also, I attach CPP file of this problem. You can download this file
0 Comments