Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives 1. To learn how to design a program using functions. 2. To review con

ID: 3627607 • Letter: O

Question

Objectives 1. To learn how to design a program using functions. 2. To review conditional statements and loops.

The Exercise program has been a big success! Now that the program is coming to a close, Exercise would like to provide its participants with a copy of the useful programs you’ve been writing all summer. However, instead of the several smaller programs you’ve provided, Exercise would like to have a single unified program. In particular, you will write a menu-driven program that provides the user with the following options: 1) Update Weight 2) Calculate BMI 3) Calorie Counter 4) Weight Calculation 5) Average Mile 6) Quit

Prior to displaying the menu, you should ask the user for their weight in pounds and height in inches. Most of these options mimic programs you have already written. The Requirements section provides information about the necessary functions and the related previous homework assignments from which the bulk of these functions should be constructed. If the user selects option 6, “Quit”, you should print out a short message thanking the user and then quit.

HERE ARE THE REQUIREMENTS:
The main program will read the user’s menu choice and invoke different functions to carry out the above subtasks. You will have to write several functions in your program and these functions must adhere to the function prototypes, pre-conditions and post-conditions specified below.
/*Pre-conditions: None
*Post-conditions: Prints the menu. */
void printmenu();

/*Pre-conditions: Weight is a positive double less than 1000.
*Post-conditions: Asks the user for their updated weight and sets weight to be equal to the new value. Weight should be updated in the main function as well. */
void update_weight(double * weight);

/*Pre-conditions: Weight is a positive double less than 1000. Height is a positive integer less than 100.
*Post-conditions: Prints the user’s current BMI and weight status. Further information can be found in Program 2A. */
void calc_BMI(double weight, int height);

/*Pre-conditions: None
*Post-conditions: Asks the user for how long they spent doing each of four activities: walking, exercising, eating, and drinking. Calculates the amount of calories burned or gained. Further information can be found in Program 2B. */
void calorie();

/*Pre-conditions: Weight is a positive double less than 1000.
*Post-conditions: Asks the user for their goal weight. Determines whether the user is trying to gain or lose weight based on their current weight and the goal weight. Then, asks the user - if they are trying to lose weight - how many calories they burn each day or – if they are trying to gain weight – how many calories they gain each day. Finally, print out how many more pounds the user has to gain or lose and how many weeks and days it will take them to reach their goal weight. Further information can be found in Program 2C. */
void weight_calc(double weight);

/*Pre-conditions: None
*Post-conditions: Asks the user how many miles they ran. Then, asks the user how long it took to run each mile. Print the average time it takes the user to run a mile. Finally, prints the user’s calculated speed in miles per hour. Further information can be found in Program 3C. */
void mile();

Here is what I have done so far:


#include <stdio.h>
#include <math.h>
#include <time.h>

#define WALK_CAL 5
#define EXERCISE_CAL 10
#define DRINK_CAL 20
#define FOOD_CAL 40
#define QUIT 6
#define CAL_FOR_1LB 3500




void printmenu();
void update_weight(double * weight);
void calc_BMI(double weight, int height);
void calorie();
void weight_calc(double weight);
void mile();

int main() {

int ans = 0;
int minWalk, minExerc;
int minDrink, minEat;
float calories;
float cal1,cal2,cal3,cal4;
int inches;
float BMI, weight;
int TotDays, weeks, days, choice;
float weightDiff, goalWeight;
float curWeight, aveBurn;
float daysFor1Lb;
int mile_run, count = 0;
float mile_time = 0;
float ave_time = 0;
float total_time = 0;
float miles_per_hour = 0;


printf ("What is your height in inches? ");
scanf ("%d", &inches);
printf ("What is your weight in pounds? ");
scanf ("%f", &weight);
printf (" ");


do {
printmenu();
scanf("%d", &ans);


if (ans < 1 || ans > QUIT)
printf("Sorry that is an invalid choice. Please try again. ");

} while (ans < 1 || ans > QUIT);

while (1) {

if (ans == 1) {


printf ("What is your current weight? ");
scanf ("%f", &curWeight);
printf(" ");



}
else if (ans == 2) {

BMI = (weight*703)/(inches*inches);
printf ("Your BMI is calculated at %.2f. ", BMI);
if (BMI < 18.5)
printf ("Your weight status is Underweight. ");
else if (BMI > 18.5 && BMI < 24.99)
printf ("Your weight status is Normal. ");
else if (BMI > 25 && BMI < 29.99)
printf ("Your weight status is Overweight. ");
else if (BMI > 30)
printf ("Your weight status is Obese. ");




}
else if (ans == 3) {

printf ("How many minutes were you walking? ");
scanf ("%d", &minWalk);
printf ("How many minutes were you exercising? ");
scanf ("%d", &minExerc);
printf ("How many minutes were you drinking? ");
scanf ("%d", &minDrink);
printf ("How many minutes were you eating? ");
scanf ("%d", &minEat);

cal1 = minWalk*WALK_CAL;
cal2 = minExerc*EXERCISE_CAL;
cal3 = minDrink*DRINK_CAL;
cal4 = minEat*FOOD_CAL;
calories = cal1+cal2-cal3-cal4;


//Here the user's output is shown if the calories are increased.
if (calories < 0)
printf ("You gained %.f calories today! ", calories / (-1));

//Here the user's ouuput is shown if the calories are burned/lost.
else
printf ("You burned %.f calories today! ", calories);

}
else if (ans == 4) {

printf ("What is your current weight? ");
scanf ("%f", &curWeight);
printf ("What is your goal weight? ");
scanf ("%f", &goalWeight);
printf ("How many calories do you burn on average each day? ");
scanf ("%f", &aveBurn);


weightDiff = abs(curWeight - goalWeight);
daysFor1Lb = (CAL_FOR_1LB/aveBurn);
TotDays = weightDiff*daysFor1Lb;
weeks = abs(TotDays/7);
days = abs(TotDays%7);

printf ("You have %.f more pounds to gain. You will reach your goal weight in %d weeks and %d days! ", weightDiff, weeks,days);
}


else if (ans == 5) {

printf ("How many miles did you run? ");
scanf ("%d", &mile_run);
printf ("How long did it take to run mile #%d ", count+1);
scanf ("%f", &mile_time);


}
else {

// Print greeting and get out of the loop!
printf("Thank you for using the Exercise UCF Program! ");
break;
}

printf(" ");

// Loop until the user enters a valid menu choice.
do {

printmenu();
scanf("%d", &ans);

// Let the user know their choice wasn't valid.
if (ans < 1 || ans > QUIT)
printf("Sorry that is an invalid choice. Please try again. ");

} while (ans < 1 || ans > QUIT);

}

system("PAUSE");
return 0;
}

// Pre-conditions: none
// Post-condition: Prompts the user with the menu.
void printmenu() {

printf("Please Select One of the Following: ");
printf("1) Update Weight ");
printf("2) Calculate BMI ");
printf("3) Calorie Counter ");
printf("4) Weight Calculation ");
printf("5) Average Mile ");
printf("6) Quit ");
}

void update_weight(double * weight) {

Here is where I'm getting struck, any help is much appreciated!!!



Explanation / Answer

please rate - thanks

this should get you started. sorry I don't know the formulas

#include <stdio.h>
#include <math.h>
#include <time.h>
#include <conio.h>
#define WALK_CAL 5
#define EXERCISE_CAL 10
#define DRINK_CAL 20
#define FOOD_CAL 40
#define QUIT 6
#define CAL_FOR_1LB 3500
void printmenu();
void update_weight(double * weight);
void calc_BMI(double weight, int height);
void calorie();
void weight_calc(double weight);
void mile();
int main() {
int ans = 0;
int inches;
double weight;

printf ("What is your height in inches? ");
scanf ("%d", &inches);
while(inches<1||inches>100)
    {printf("invalid entry ");
    printf ("What is your height in inches? ");
scanf ("%d", &inches);
   }
update_weight(&weight);
printf (" ");
do {
printmenu();
scanf("%d", &ans);
while (ans < 1 || ans > QUIT)
    {printf("Sorry that is an invalid choice. Please try again. ");
     printmenu();
     scanf("%d", &ans);
     }
if (ans == 1) {
   update_weight(&weight);
  
   }
else if (ans == 2) {
   calc_BMI(weight,inches);
    
}
else if (ans == 3) {
    calorie();
}
else if (ans == 4) {
    weight_calc(weight);
    
     }
else if (ans == 5) {
     mile();  

}
else {

// Print greeting and get out of the loop!
   printf("Thank you for using the Exercise UCF Program! ");
   getch();
   return 0;
     }

}while(1);
}
void mile()
{int mile_run, count = 0;
double mile_time = 0,sum=0;
printf ("How many miles did you run? ");
     scanf ("%d", &mile_run);
     for(count=1;count<=mile_run;count++)
          {printf ("How long did it take to run mile #%d ", count);
           scanf ("%lf", &mile_time);
           sum+=mile_time;
           }  
     printf("average time to run a mile %f ",sum/(double)mile_run );
      printf("calculated speed %f mph ",sum/mile_run/60. );

}
void calc_BMI(double weight, int inches)
{double BMI;
     BMI = (weight*703)/(inches*inches);
     printf ("Your BMI is calculated at %.2f. ", BMI);
     if (BMI < 18.5)
        printf ("Your weight status is Underweight. ");
     else if (BMI > 18.5 && BMI < 24.99)
        printf ("Your weight status is Normal. ");
     else if (BMI > 25 && BMI < 29.99)
        printf ("Your weight status is Overweight. ");
     else if (BMI > 30)
        printf ("Your weight status is Obese. ");
        }
       
void calorie()
{double calories;
double cal1,cal2,cal3,cal4;
int minWalk, minExerc;
int minDrink, minEat;
     printf ("How many minutes were you walking? ");
     scanf ("%d", &minWalk);
     printf ("How many minutes were you exercising? ");
     scanf ("%d", &minExerc);
     printf ("How many minutes were you drinking? ");
     scanf ("%d", &minDrink);
     printf ("How many minutes were you eating? ");
     scanf ("%d", &minEat);

     cal1 = minWalk*WALK_CAL;
     cal2 = minExerc*EXERCISE_CAL;
     cal3 = minDrink*DRINK_CAL;
     cal4 = minEat*FOOD_CAL;
     calories = cal1+cal2-cal3-cal4;


     //Here the user's output is shown if the calories are increased.
       if (calories < 0)
           printf ("You gained %.f calories today! ", calories / (-1));

       //Here the user's ouuput is shown if the calories are burned/lost.
       else
           printf ("You burned %.f calories today! ", calories);

}
void weight_calc(double curWeight)
{int TotDays, weeks, days, choice;
double weightDiff, goalWeight;
double aveBurn;
double daysFor1Lb;

double ave_time = 0;
double total_time = 0;
double miles_per_hour = 0;
     printf ("What is your goal weight? ");
     scanf ("%lf", &goalWeight);
     printf ("How many calories do you burn on average each day? ");
     scanf ("%lf", &aveBurn);


     weightDiff = abs(curWeight - goalWeight);
     daysFor1Lb = (CAL_FOR_1LB/aveBurn);
     TotDays = weightDiff*daysFor1Lb;
     weeks = abs(TotDays/7);
     days = abs(TotDays%7);

     printf ("You have %.f more pounds to gain. You will reach your goal weight in %d weeks and %d days! ", weightDiff, weeks,days);
}


// Pre-conditions: none
// Post-condition: Prompts the user with the menu.
void printmenu() {

printf("Please Select One of the Following: ");
printf("1) Update Weight ");
printf("2) Calculate BMI ");
printf("3) Calorie Counter ");
printf("4) Weight Calculation ");
printf("5) Average Mile ");
printf("6) Quit ");
}

void update_weight(double *weight) {
printf ("What is your current weight? ");
   scanf ("%lf", weight);
while(*weight<1||*weight>1000)
    {printf("invalid entry ");
    printf ("What is your current weight? ");
   scanf ("%lf", weight);
   }
   printf(" ");

}