Click here to Skip to main content
15,881,882 members

How to use memory that will last after the program finishes, How read a input and send a simple output from a usb and send a output to that usb.

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.




C++
#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

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

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.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900