Click here to Skip to main content

Chris Gilchrist asked:

Open original thread
I have this program and I need help with 2 issues
 
It needs a way to save the information for thr[acct] and timesave[acct]. I need a way to save the information so it can be used later. I know I am supposed to write another file for it to store and pull from but I do not know how to go about it.
 
It needs a way to read a square wave signal from a specified USB and it needs a way to send a output signal high or low to the USB. I have been looking around but I have not found a way to go about it.
 
Any help with this would be greatly appreciated.
 

 

#include <stdio.h>
#include <stdlib.h>

void accountselect();
 
    int timesave[20]={0};
    int thr[20]={0};
    int p; //“input from the heart rate monitor”
    int p1;
    int tvon; //“output from program to usb or other output”

void accountselect()
{
    int input=0;
     
    //system("clrscr");
    printf( "Enter your Account Number, 0 to quit: " );
    scanf( "%d", &input );
    switch ( input ) {
        case 1-19:            /* Note the colon, not a semicolon */
            workoutbegin(input);
            break;
        case 0:        
            printf( "Thanks for using exervision\n" );
            break;
        default:            
            printf( "Bad input, quitting!\n" );
            break;
    }
    getch();
}
 
void accountset()
{
    int age;                          /* Need a age... */
    char sex;
 
    // set account number
    //fscanf
    //fprintf
    //
    int acct=1;
      
    printf( "Please enter your age: ");  /* Asks for age */
    scanf( "%d", &age );                 /* The input is put in age */
    printf("please enter your gender (m/f): "); /*asks for sex */
 
    // this should be fixed some time to not read the return as the character
	sex=getch();
	sex=getch();
	
    if (sex=='f' ) {                  /* If the sex is f */
        thr[acct]=226-age;
    }
    else if (sex=='m') {            /* if the sex is m */ 
        thr[acct] = 220-age;
    }
    else {
        printf( "invalid entry\n" );     /* Executed if no other statement is */
        //break;
    }
    printf ("Your target heart rate is %d\n" ,thr[acct] ); /* Just to show you it works... */
    printf("Your account number is %d.  Please remember this number for future use.\n",acct);
    system("Pause");
    //return 0;
}
 
void account()
{
    int input;
     
    //system("clr");
    printf( "1. Run Exervision\n" );
    printf( "2. Create account\n" );
    printf( "3. quit\n" );
    printf( "Selection: " );
    scanf( "%d", &input );
    switch ( input ) {
        case 1:            /* uses account* to run*/
            accountselect();
            break;
        case 2:          
            accountset();
            break;
        case 3:        
            printf( "Thanks for using exervision\n" );
            break;
        default:            
            printf( "Bad input, quitting!\n" );
            break;
 }
    getchar();
 
}
 

int workoutbegin(int acct)
{
/*
	select accounts 
		account 1, 2, 3,q			
			int age
			int sex
			Printf select Run or Setup
			if Setup then printf enter age
			getchar=>age
			Printf select sex (m,f)
			getchar=>sex
			if sex=m then thr1=220-age
			else thr1=226-age
*/			
    printf("start working out\n");
    printf("work out if you wish to stop watching TV and save any time left press q");
 
    p1=p;
    //I need the program to wait 1 minute
    //time_t start,end;
    //start=clock();//predefined  function in c
    //after the user defined function does its work
    //end=clock();
    system("ping -n 60 127.0.0.1");
    //t=(end-start)/CLOCKS_PER_SEC;
    //or
    
    /*  //this section won't work without some sort of semaphore 
    scanf("%s",&selection);//q then return to main 
 
    if strcmp(selection,"q")
        break;
    */
 
    if (p >thr[acct])
    {
       tvon=1;
       timesave[acct]++;
       p1=p;
       printf("Congradulations in Target Heart Rate zone.  You earned 1 minute extra time that you can save or use at the end of your work out/n");
       workoutbegin(acct);
    }
    
    else if (p > p1)
    {
        tvon=1;
        printf("You may continue to watch tv, but you are not yet in your Target Heart Rate zone.\n");
        p1 =p;
        workoutbegin(acct);
    }
    
    else if (p0)
    {
        tvon=1;
        timesave[acct]--;
        p1 =p;
        printf("You are watching on borrowed time.  Time is being taken from your savings.\n");
        workoutbegin(acct);
    }
 
    else if (p
    {
        printf ("YOU'RE NOT WORKING OUT HARD ENOUGH.  WORK OUT HARDER OR THE TV WILL TURN OFF IN ONE MINUTE!\n");
    
        system("ping -n 60 127.0.0.1");
        
        if (p<p1)>
        printf ("Sorry workout was inefficient and you are out of saved time. No TV for you.\n");
        tvon=0;
        //account select
    }
}
 

int main(int argc, char *argv[])
{
    account();
    
    return 0;
    system("PAUSE");	
}
[EDIT]
Added tags for code formatting. Even in the unedited version some text at p and p1 conditions is wrong (probably destroyed when pasting).
[/EDIT]
Tags: C

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100