Thread: Pedometer

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    Pedometer

    Doing this project and have figured out quite a few things but
    I need to figure out how to get the Reports so that it will output the following information:
    Average calories burned per day over 7 days
    Average number of miles traveled " "
    Day on which the highest number of calories were expended
    Day on which the lowest were expended
    Day on which the highest number of miles were traveled
    Day on which the lowest " "

    Any help will be greatly appreciated!...
    here is my code:
    Code:
    #include <stdio.h>
    
    int mainPage (int First, int Second, int Third);
    void inputDays (double *mile, double *calories, double weight);
    
    int main (void)
    
    {
         int menuChoice;
    	double weight;
    	char initials , initials2 , initials3;
    	char cr;
    	double mile1, cal1;
    	double mile2, mile3 , mile4, mile5, mile6, mile7;
    	double cal2, cal3, cal4, cal5, cal6, cal7;
    	int first, second, third;
    
    	first = 1;
    	second = 0;
    	third = 0;
    
    	do
    	{
    		menuChoice = mainPage (first, second, third);
    		printf ("menuChoice %d\n", menuChoice);
    
    		if (menuChoice == 2)
    		{
    			first = 0;
    			second = 1;
    			third = 0;
    			printf ("Enter initials \n");
    			scanf ("%c%c%c%c", &initials, &initials2, &initials3, &cr);
    			printf ("Enter weight \n");
    			scanf ("%lf", &weight);
    	}
    		if (menuChoice ==3)
    	{
    			printf ("Enter initials \n");
    			scanf ("%c%c%c%c", &initials, &initials2, &initials3, &cr);
    			printf ("Enter weight \n");
    			scanf ("%lf", &weight);
           }
    		if (menuChoice ==4)
           {
    
                  first = 1;
    	       second = 0;
    	        third = 0;
                       inputDays (&mile1, &cal1, weight);
    		      inputDays (&mile2, &cal2, weight);
    			inputDays (&mile3, &cal3, weight);
    			inputDays (&mile4, &cal4, weight);
    			inputDays (&mile5, &cal5, weight);
    			inputDays (&mile6, &cal6, weight);
    			inputDays (&mile7, &cal7, weight);
    
             }
    } while (menuChoice != 1);
    
    	return (0);
    
    
    }
    
    void inputDays (double *mile, double *calories, double weight)
    {
    	double milesPerHour;
    	double Mets;
    	double minutes;
    	double steps;
    	double kg;
    
    	     printf("Enter distance in steps:");
    	      scanf( "%lf", &steps);
    	      printf ("Enter minutes walked:");
    	       scanf("%lf", &minutes);
    
    	kg = weight * 2.2;
    
    	milesPerHour = (steps/60) / 60;
    
    	*mile = steps /2000;
    
    	    if (milesPerHour < 3)
    	{
    		Mets = 3;
           }
    	    if (milesPerHour >3 || milesPerHour <= 4.5)
    	{
    		Mets = 6;
            }
    	if (milesPerHour > 4.5)
            {
    		Mets = 7;
            }
    
    	*calories = minutes * ( ( Mets * 3.5 * kg) /200);
    	
    
    
    }
    int mainPage (int First, int Second, int Third)
    
    {
        int option;
    	int min , max;
    
    	min = 1;
    
    	do
    	{
    		printf ("1 - quit \n");
    
    		if (First ==1)
    	   {
    			printf("2 - Create \n");
    			max = 2;
    	   }
    		if (Second ==1 || Third ==1 )
    	 {
    		printf ("3 -Edit\n");
    		printf ("4 - Start recording \n");
    			max =4;
    	 }
    		if (Third ==1)
            {
                 printf("5 - Reports \n");
    			max = 5;
             }
    		scanf ("%d", &option);
       } while ( option < min || option > max);
    
    	return (option);
    }

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Consider storing the miles traveled/day and calories spent/day in a 2D array instead of 14 double variables, as in
    Code:
    double weight[7][2];    /* where weight[0][0] is the miles traveled and weight[0][1] is the calories spent on day one */
    Now walk along the array to generate the reports. Besides you won't have to call inputDays() seven times.
    Last edited by itCbitC; 11-22-2009 at 10:28 PM.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    4
    Quote Originally Posted by itCbitC View Post
    Consider storing the miles traveled/day and calories spent/day in a 2D array instead of 14 double variables, as in
    Code:
    double weight[7][2];    /* where weight[0][0] is the miles traveled and weight[0][1] is the calories spent on day one */
    Now walk along the array to generate the reports. Besides you won't have to call inputDays() seven times.
    so..would I just replace the inputDays function altogether. I hadn't learned about arrays before but went to the tutorials on it and it appears that it would help. Thank you.

Popular pages Recent additions subscribe to a feed