In: C Programming|Windows
20 Dec 2011Question:
Create a calorimeter to tell the “user” the pounds lost. It doesn’t ACTUALLY measure the number of calories you burn or the number of calories you ingest. Instead, it makes four assumptions:
1) When walking, you burn 5 calories/minute.
2) When standing in line, you burn 2 calorie/minute.
3) When you are consuming solid food, you ingest 40 calories/minute.
4) When you are consuming a drink, you ingest 20 calories/minute.
The calorimeter is “smart enough” to know which of the four activities you are engaging in at any point in time, and at the end of the day, compiles a tally of how many minutes you spent doing each of these four activities. Write a program that takes these four values as input and outputs the pounds lost (we want a positive message for our clients). If the user has gained weight, simply print out a negative number for weight lost. Note, use the following constants for this problem:
#define WALK_CAL 5
#define STAND_CAL 2
#define DRINK_CAL 20
#define FOOD_CAL 40
#define CALS_PER_POUND 3500
Input Specification
1. All four values will be non-negative integers less than 720, representing the number of minutes spent for each of the four activities.
Output Specification
Output a single line of the following format telling the user how many pounds they lost, rounded to 3 decimal places.
You lost X.XXX pounds today!
The code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <stdlib.h> #include <stdio.h> //Constants #define WALK_CAL 5 #define STAND_CAL 2 #define DRINK_CAL 20 #define FOOD_CAL 40 #define CALS_PER_POUND 3500 main (void) { //Declare variables int walk, stand, drink, food; float cal_gain, cal_lost, pounds_lost, final_cal; //Ask user how many minutes walking printf("How many minutes were you walking?\n"); scanf("%d", &walk); //Ask user how many minutes tanding printf("How many minutes were you standing?\n"); scanf("%d", &stand); //Calculate lost calories cal_lost=(walk*WALK_CAL)+(stand*STAND_CAL); //Ask user how many minutes drinking printf("How many minutes were you drinking?\n"); scanf("%d", &drink); //Ask user how many mnutes eating printf("How many minutes were you eating?\n"); scanf("%d", &food); //Calculate gained and lost calories cal_gain=(drink*DRINK_CAL)+(food*FOOD_CAL); //Calculate final calories final_cal=(cal_lost)-(cal_gain); //printf("Total Calories %.0f\n", final_cal); //Convert to pounds pounds_lost=(final_cal/CALS_PER_POUND); //Show result printf("You lost %.3f pounds today!\n", pounds_lost); system("pause"); return 0; } |
Output Sample
