85.0k views
3 votes
How Many Calories? A bag of cookies holds 30 cookies. The calorie information on the bag claims that there are 10 "servings" in the bag and that a serving equals 300 calories. Write a program that asks the user to input how many cookies he or she actually ate and then reports how many total calories were consumed.

User Vikash B
by
6.6k points

1 Answer

0 votes

Answer:

// program in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// Constant Variables

const int c_per_bag = 30,

ser_per_bag = 10,

cal_per_ser = 300;

// Variables

float c_eaten,

ser_eaten,

cal_consumed,

cookies_per_serving = c_per_bag / ser_per_bag;

cout << "How many cookies eaten? ";

// read cookies eaten

cin >> c_eaten;

// find number of servings

ser_eaten = c_eaten / cookies_per_serving;

// find total caloires consumed

cal_consumed = ser_eaten * cal_per_ser;

// print cookies eaten

cout << "Number of cookies eaten = "<<c_eaten<<endl;

// print calories consumed

cout << "Number of calories consumed = "<<cal_consumed<<endl;

return 0;

}

Step-by-step explanation:

Find the number of servings in a bag and calories consumed in one servings.Read the number of cookies eaten by user.Then find the eaten servings by dividing cookies eaten with cookies per servings.Then find the calories consumed by multiply eaten servings with calories per servings.Print the eaten cookies and calories consumed.

Output:

How many cookies eaten? 25

Number of cookies eaten = 25

Number of calories consumed = 2500

User Raphael Medaer
by
5.6k points