I am trying to get my code to work for a pedometer I have to do for class. I seem to be running into the problem of it not wanting to compute the information I have given it. If you could please help me out and let me know where I am going wrong I would greatly appreciate it. Here is the code I have:
Code:
#include<stdio.h>
#include<string.h>
typedef struct{
char name[13];
double weight;
double avg_miles;
double lowmiles;
double highmiles;
double avg_cal;
double lowcal;
double highcal;
double wspeed;
double tot_miles;
double tot_cal;
int days;
double min;
int MET;
double calburned;
double miles;
double distance;
double kg;
} user;
void menu1 (user person);
void new_user (user person);
void existing_user(user person);
double MET_calc (user person);
double weightkg (user person);
double calburned (user person);
double avg_cal (user person);
void temp_low_cal (user person);
void temp_high_cal (user person);
void temp_low_miles (user person);
void temp_high_miles( user person);
double avg_miles(user person);
double miles(user person);
double distance(user person);
void print(user person);
int main(void)
{
user person;
menu1(person);
person.days=0;
/*new_user (person);
existing_user(person);*/
return(0);
}
void menu1 (user person) {
int menu;
printf("\n1. Choose Existing User \n2. Create New User \n3. Exit");
printf("\nChoose either 1 or 2 to continue: ");
scanf("%d", &menu);
if(menu == 2) {
new_user(person);
}
else {
if(menu == 1) {
existing_user(person);
}
}
}
void new_user (user person) {
printf("\nEnter Name: ");
scanf("%s", &person.name);
printf("\nEnter Weight: ");
scanf("%lf", &person.weight);
printf("\nEnter walking speed in MPH: ");
scanf("%lf", &person.wspeed);
person.MET= MET_calc(person);
menu1(person);
}
void existing_user(user person) {
int menu;
printf("\nChoose existing user: ");
scanf("%s", &person);
printf("\nChoose either \n1. Data Entry \n2. Report: ");
scanf("%d", &menu);
while(menu !=1 && menu !=2) {
printf("\nMust choose either 1 or 2 to continue.");
scanf("%d", &menu); }
if(menu == 1) {
printf("\nMinutes walked: ");
scanf("%lf", &person.min);
}
if(menu == 2) {
print(person);
}
existing_user(person);
}
double MET_calc (user person) {
int MET;
if(person.wspeed < 3) {
MET = 3; }
if(person.wspeed >= 3 && person.wspeed< 4.5) {
MET = 6; }
if(person.wspeed >= 4.5) {
MET = 7; }
return MET;
}
double weightkg (user person) {
double kg;
kg = person.weight / 2.2;
return kg;
}
double calburned (user person) {
double calburned;
int MET;
double min;
double kg;
person.MET = MET_calc(person);
MET = person.MET;
min = person.min;
person.kg = weightkg(person);
kg = person.kg;
calburned = min * ((MET * 3.5 * kg) / 200);
return calburned;
}
double avg_cal (user person) {
double tot_cal;
double avg_cal;
/*double cal;*/
person.days = person.days+1;
person.calburned = calburned(person);
tot_cal = person.tot_cal + person.calburned;
/*tot_day = day;*/
avg_cal = tot_cal /person.days;
return avg_cal;
}
void temp_low_cal (user person) {
double temp;
temp = calburned(person);
if(temp <= person.lowcal) {
person.lowcal = temp; }
}
void temp_high_cal (user person) {
double temp;
temp = calburned(person);
if(temp >= person.highcal) {
person.highcal = temp; }
}
void temp_low_miles (user person) {
double temp;
temp =person.lowmiles;
if(temp <= person.lowmiles) {
person.lowmiles = temp; }
}
void temp_high_miles (user person) {
double temp;
temp = person.highmiles;
if(temp >= person.highmiles) {
person.highmiles = temp; }
}
double avg_miles(user person) {
double avg_miles;
double tot_miles;
tot_miles = person.tot_miles + person.miles;
person.days = person.days + 1;
avg_miles = person.tot_miles / person.days;
return avg_miles;
}
double miles(user person) {
double hours;
double miles;
double wspeed;
double min;
min = person.min;
wspeed = person.wspeed;
hours = min / 60;
person.miles = miles;
miles = hours * wspeed;
return miles;
}
void print(user person) {
double a;
double d;
double e;
double h;
printf("%d", person.days);
d = calburned(person);
printf("\nTotal calories is %lf", &d);
a = avg_cal(person);
printf("\nAverage calories is %lf", &a);
temp_low_cal(person);
printf("\nLowest calories is %lf", &temp_low_cal);
temp_high_cal(person);
printf("\nHighest calories is %lf", &temp_high_cal);
e = avg_miles(person);
printf("\nAverage distance is %lf", &e);
temp_low_miles(person);
printf("\nLowest distance is %lf", &temp_low_miles);
temp_high_miles(person);
printf("\nHighest distance is %lf", &temp_high_miles);
h = miles(person);
printf("\nTotal distance is %lf", &h);
}