Question

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 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...
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 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...

  • 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...

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

    Write the following C++ program that searches for specified words hidden within a matrix of letters. 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 be read into your matrix row...

  • 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...

  • Problem 1C: Chapter: CHCC Problem: 1C Say It Ain't So! Is This the Real Thing? INTRODUCTION...

    Problem 1C: Chapter: CHCC Problem: 1C Say It Ain't So! Is This the Real Thing? INTRODUCTION David Ortega is the lead researcher for an upscale restaurant group hoping to add another chain that would compete directly with the upscale Smith and Wollensky restaurants (http://www.smith-andwollensky.com). The Smith and Wollensky Restaurant Group operates a handful of iconic restaurants around the country. The average check for a customer at Smith and Wollensky is approximately $80 to $90. Whenever a new venture of this...

  • 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...

  • Please read the attached article from the New York Times and write a short paper answering...

    Please read the attached article from the New York Times and write a short paper answering the below questions. There is no length minimum for the essay. I would anticipate approximately 1-2 pages double-spaced, 12pt Times New Roman font to address all required elements. Papers over 2 pages will receive an automatic reduction of 50%. Your task is to accomplish two goals in your paper: Analyze a business problem(s) presented in the article and describe its effect on the business...

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