233k views
1 vote
design and write a c program that prompts your user for the number of cookies that they ate from one of these bags and then displays the total number of calories they consumed.

1 Answer

3 votes

Final answer:

To design a C program that prompts the user for the number of cookies eaten and displays the total number of calories consumed, you can follow these steps.

Step-by-step explanation:

To design a C program that prompts the user for the number of cookies eaten and displays the total number of calories consumed, you can follow these steps:

  1. Declare a variable to store the number of cookies eaten.
  2. Prompt the user to enter the number of cookies and store it in the variable.
  3. Calculate the total number of calories by multiplying the number of cookies by the number of calories per cookie. You can assume a fixed number of calories per cookie.
  4. Display the total number of calories consumed to the user.

Here's an example code snippet to demonstrate this:

#include <stdio.h>

int main() {
int cookiesEaten;
int caloriesPerCookie = 50; // Assume each cookie has 50 calories
int totalCalories;

printf("Enter the number of cookies eaten: ");
scanf("%d", &cookiesEaten);

totalCalories = cookiesEaten * caloriesPerCookie;

printf("Total calories consumed: %d\\", totalCalories);

return 0;
}

User Ajaykumar Mistry
by
9.0k points