Deitel & Deitel, C How to Program 6th Edition, Exercise 3.48
/*3.48 (Target-Heart-Rate Calculator) While exercising, you can use a heart-rate monitor to see
that your heart rate stays within a safe range suggested by your trainers and doctors. According to the
American Heart Association (AHA) (www.americanheart.org/presenter.jhtml?identifier=4736),
the formula for calculating your maximum heart rate in beats per minute is 220 minus your age in
years. Your target heart rate is a range that is 50–85% of your maximum heart rate. [Note: These formulas
are estimates provided by the AHA. Maximum and target heart rates may vary based on the
health, fitness and gender of the individual. Always consult a physician or qualified health care professional
before beginning or modifying an exercise program.] Create a program that reads the user’s
birthday and the current day (each consisting of the month, day and year). Your program should calculate
and display the person’s age (in years), the person’s maximum heart rate and the person’s target
heart rate range.*/
#include <stdio.h>
int main() {
int bday, bmonth, byear, day, month, year, age, max;
printf("Enter your birthday(Ex:18 03 1995): ");
scanf("%d%d%d", &bday, &bmonth, &byear);
printf("Enter current day(Ex: 16 12 2017): ");
scanf("%d%d%d", &day, &month, &year);
if (month > bmonth || (month == bmonth && day >= bday))
age = year - byear;
else
age = year - byear - 1;
max = 220 - age;
printf("Your age is: %d \n", age);
printf("Your max heart rate is:%d \n", 220-age);
printf("Your target heart rate range is between %d-%d\n", max/2, max*85/100 );
return 0;
}
that your heart rate stays within a safe range suggested by your trainers and doctors. According to the
American Heart Association (AHA) (www.americanheart.org/presenter.jhtml?identifier=4736),
the formula for calculating your maximum heart rate in beats per minute is 220 minus your age in
years. Your target heart rate is a range that is 50–85% of your maximum heart rate. [Note: These formulas
are estimates provided by the AHA. Maximum and target heart rates may vary based on the
health, fitness and gender of the individual. Always consult a physician or qualified health care professional
before beginning or modifying an exercise program.] Create a program that reads the user’s
birthday and the current day (each consisting of the month, day and year). Your program should calculate
and display the person’s age (in years), the person’s maximum heart rate and the person’s target
heart rate range.*/
#include <stdio.h>
int main() {
int bday, bmonth, byear, day, month, year, age, max;
printf("Enter your birthday(Ex:18 03 1995): ");
scanf("%d%d%d", &bday, &bmonth, &byear);
printf("Enter current day(Ex: 16 12 2017): ");
scanf("%d%d%d", &day, &month, &year);
if (month > bmonth || (month == bmonth && day >= bday))
age = year - byear;
else
age = year - byear - 1;
max = 220 - age;
printf("Your age is: %d \n", age);
printf("Your max heart rate is:%d \n", 220-age);
printf("Your target heart rate range is between %d-%d\n", max/2, max*85/100 );
return 0;
}
Comments
Post a Comment