Question

Hello. I want to write a function in C program to track calories for specified fitness activities...

Hello. I want to write a function in C program to track calories for specified fitness activities i.e. run, walk, bike etc. I am trying to make an array with the activities and return calories burned per minute for each workout. The function will keep running until user tells it to stop. "maybe 'while' loop (Y/N)" or something like that. The main function will call the activity function and a few printf/scanf. My code looks pretty bad so if you could at least get me started, that would help a lot. Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question. Based on the question, here is a C program that you can adopt.

Comments are given inline, we are considering only running, walking and driving

Running consumes 12 calroeis/min

Walking consumes 10 calroeis/min

Driving consumes 8 calroeis/min

========================================================================================

#include<stdio.h>

// calculate the total calrories burnt for each acitivity and sum them up

// returns the tototal claories burnt

double calculateCaloriesBurnt(double *calories, int *mins, int size){

               

                double caloriesBurnt=0.0;

                int i=0;

                for(;i<size;i++){

                                caloriesBurnt+= *(calories+i)* (*(mins+i));

                }

                return caloriesBurnt;

               

}

int main(){

               

                // assuming 12 calories burnt by running in 1 min

                // assuming 10 calories burnt by walking in 1 min

                // assuming 8 calories burnt by biking in 1 min

                double calories_per_min[]={12,10,8};

                // this array will stores the total mins spent, initially all set to 0

                // for 3 activities we have a size of 3

                int mins[3]={0,0,0};

                while(1){

                                int minutes;

                                printf("Enter the number of mins you have run(whole number): ");

                                scanf("%d",&minutes);

                                mins[0]=mins[0]+minutes;

                                printf("Enter the number of mins you have walked(whole number): ");

                                scanf("%d",&minutes);

                                mins[1]=mins[1]+minutes;

                                printf("Enter the number of mins you have drived(whole number): ");

                                scanf("%d",&minutes);

                                mins[2]=mins[2]+minutes;

                               

                                char c='y';

                                printf("\nDo you want to add more (y/n): ");

                                scanf(" %c",&c);

                                if(c=='n')break;

                }

               

                double caloriesBurnt = calculateCaloriesBurnt(calories_per_min,mins,3);

                printf("\nTotal mins you have run    : %d",mins[0]);

                printf("\nTotal mins you have walked : %d",mins[1]);

                printf("\nTotal mins you have drived : %d",mins[2]);

                printf("\nTotal calories burnt       : %.2lf",caloriesBurnt);

               

}

========================================================================================

thanks, let me know in case you need to change the code.

Add a comment
Know the answer?
Add Answer to:
Hello. I want to write a function in C program to track calories for specified fitness activities...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello. I want to write a function in C program to track calories for specified fitness...

    Hello. I want to write a function in C program to track calories for specified fitness activities i.e. run, walk, bike etc. I am trying to make an array with the activities and return calories burned per minute for each workout. The function will keep running until user tells it to stop. "maybe 'while' loop (Y/N)" or something like that. The main function will call the activity function and a few printf/scanf. My code looks pretty bad so if you...

  • Write a program that searches for specified words hidden within a matrix of letters. C++ HELP...

    Write a program that searches for specified words hidden within a matrix of letters. C++ HELP -pls keep basic as possible, thanksssss 1. Read a file that the user specifies. The file will first specify the dimensions of the matrix (e.g., 20 30). These two numbers specify the number of rows in the matrix and then the number of columns in the matrix. 2. Following these two numbers, there will be a number of rows of letters. These letters should...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • Hello! Could you please write your own four paragraph (5-6 sentences per paragraph) take away or...

    Hello! Could you please write your own four paragraph (5-6 sentences per paragraph) take away or reflection of the below information? Please complete in 24 hours if possible. Thank you! RIS BOHNET THINKS firms are wasting their money on diversity training. The problem is, most programs just don’t work. Rather than run more workshops or try to eradicate the biases that cause discrimination, she says, companies need to redesign their processes to prevent biased choices in the first place. Bohnet...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT