Pedometer

This is a discussion on Pedometer within the C Programming forums, part of the General Programming Boards category; I am trying to get my code to work for a pedometer I have to do for class. I seem ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    Pedometer

    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);
    }

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    You might want to read this: C Board - Announcements in Forum : General Programming Boards

    Try to narrow down where your problem is and go from there.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    Homework

    This is just something we were doing in class and I did everything but can't get the program to compute the information. All I was wondering is if someone could possibly see what I am missing or where I went wrong. I can't seem to figure it out.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    First problem is you shouldn't pass the entire struct to your functions. Inside the functions you are assigning various elements of the LOCAL structs... and this is never reflected when you exit the function. Instead you should pass the pointer to the struct, and the functions should accept address of structure. The elements are accessed using '->'
    Code:
    void new_user(user *person) {
    person->weight = 123.0;
    }
    ...
    
    new_user(&person);
    ...
    
    printf("person weight: %lf\n", person.weight);

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    Ok so I got it to show values. Now the problem I am having is that I need to add to it like a daily basis type thing. It needs to keep track for 365 days. So when I am doing the average calories and average miles it needs to be saved so it can add to it to get me the average so far. here is what I have.

    Code:
    double avg_cal(user person) {
    
    	int tot_day;
    	double avg_cal;
    
    	person.days = 0;
    
    	tot_day = person.days + 1;
    
    	avg_cal = calburned(person) / tot_day;
    
    	return avg_cal;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pedometer
    By mulvaslips in forum C Programming
    Replies: 2
    Last Post: 11-23-2009, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21