Thread: need help with Tracking user login

  1. #16
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    I can try but I am posting via iPhone try something like this

    Code:
    bool PlaceData(int );
    
    int myarray[5000];
    
    int main()
    {
       // set all values of array to -1 
       int value=0;
       while(value != -1)
       {
       cout<<"Enter a value: "; 
       cin>>value;
       if(value != -1) PlaceData(value);
       }
       return 0;
    }
    
    bool PlaceData(int v)
    {
       for(int i = 0; i < 5000;i++)
       {
          if(myarray[i] == -1)// open spot
          {
             myarray[i] = v;
             return true;
          }
       }
       return false;
    }

  2. #17
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    Code:
    #include <iostream>
    #include <cstdlib>
    
    
    using namespace std;
    void Displaylab(int *lab,int size)
    {
        int i;
         for(i = 0; i < size; i++)
         lab[i] = 0;
         lab[i] = -1;
         return;
    }
    int **dynArray(int row, int cols)
    {
        int **myPtr;
        int lab[4];
        myPtr = new int *[row];
        for(int i = 0; i < row; i++)
        myPtr[i] = new int[lab[i]];
        int i = 0;
        int size;
        if(myPtr[i] == 0)
        cout<<"empty";
        return myPtr;   
    }
    
    
    void getinput(int ID,int &Station,int &labnumb)
    {
         cout<<"Enter your ID number: "<<endl;
         cin>>ID;
          cout<<"Enter your station number: "<<endl;
         cin>>Station;
          cout<<"Enter your lab number: "<<endl;
         cin>>labnumb;
         return;  
    }
    void logout(int **Array,int ID,int row,int lab[])
    {
         int r,c;
         if(search(**Array,ID,row,r,c,lab))     //Here is my mistake
    
         dynArray[r][c] = 0;                        //this one also.Need some help on debugging or fix it
         cout<< "You have been logged out."<<endl;
        return;
    }
    void login(int **Array,int ID,int &Station,int &labnumb)
    {
         getinput(ID,Station,labnumb);
         Array[labnumb-1][Station-1] = ID;  
         return;
         
    }
    bool search(int **Array,int ID,int row,int &r,int &c,int lab[])
    {
         cout<<"Enter user ID to check: "<<endl;
         cin>>ID;
         bool found = false;
         for(int i = 0; i < row;i++)
         for(int j = 0; j < lab[i];j++)
         if(ID == Array[i][j])
         {
          found = true;
          r = i;
          c = j;
          
          }
         return found;
    }     
    
    
    void Menu(int **Array,int ID,int &Station,int &labnumb,int row,int &r,int &c,int lab[])
    {
         int choice;
         cout<<"Enter 1 for login, 2 for search,3 for exit. "<<endl;
         cin>>choice;
         if(choice == 1)
             login(Array,ID,Station,labnumb);
         if(choice == 2)
             search(Array,ID,row,r,c,lab);
         if(choice == 3)
             exit(0);
         return;
    }
    
    
    int main()
    {
        int lab[4];
        lab[0] = 5;
        lab[1] = 6;
        lab[2] = 4;
        lab[3] = 3;
        int **labmain;
         labmain = new int*[4];
        for(int i = 0; i <4 ; i++)
        {
                *(labmain + i) = new int;
        }
        labmain = dynArray(4,7);
        int ID,Station,row,r,c,labnumb;
         Menu(labmain,ID,Station,labnumb,row,r,c,lab);
          system("PAUSE");
          return 0;
    }
    Here is my completing code but still with some mistake and i have tried a few days to debug it but I can't understand where that mistake get wrong

  3. #18
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Are we storing rows and columns that they are sitting in as well?

  4. #19
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Code:
    C:\Users\David\Desktop\Cboard\eric\main.cpp||In function 'int** dynArray(int, int)':|                   
    C:\Users\David\Desktop\Cboard\eric\main.cpp|22|warning: unused variable 'size'|                        You are not using the variable in the function why even declare it?
    C:\Users\David\Desktop\Cboard\eric\main.cpp||In function 'void logout(int**, int, int, int*)':|
    C:\Users\David\Desktop\Cboard\eric\main.cpp|42|error: 'search' was not declared in this scope|           Search is declared after the function you are using it in you can't do that.
    C:\Users\David\Desktop\Cboard\eric\main.cpp|44|warning: pointer to a function used in arithmetic|          A pointer is not a value you want to use in arithmetic a pointer is likely not the same value you want to use
    C:\Users\David\Desktop\Cboard\eric\main.cpp|44|warning: pointer to a function used in arithmetic|          Ditto
    C:\Users\David\Desktop\Cboard\eric\main.cpp|44|error: assignment of read-only location '*(dynArray + (((unsigned int)r) + ((unsigned int)c)))'|               What is dynArray?  I don't even see it declared unless I am overlooking something.
    C:\Users\David\Desktop\Cboard\eric\main.cpp|44|error: cannot convert 'int' to 'int**(int, int)' in assignment|
    ||=== Build finished: 3 errors, 3 warnings ===|

  5. #20
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    Hm... no really. Because In my search function i have search for the user login and save the position so that when I call function in the logout function it can search and logout the user forgot to logout

  6. #21
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Code:
    void logout(int **Array,int ID,int row,int lab[])
    {
         int r,c;
         if(search(**Array,ID,row,r,c,lab))     //Here is my mistake
     
         dynArray[r][c] = 0;                        //this one also.Need some help on debugging or fix it
         cout<< "You have been logged out."<<endl;
        return;
    }
    when you call search you are not passing your array by using the double ** in the function call. Do keep that in mind.

    Code:
    dynArray[r][c] = 0;
    Umm it is a function what are you trying to do call the function?

    Maybe use:
    Code:
    dynArray(r,c) = 0;

  7. #22
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    I wondering the second part I'm calling the position of the user login in the search function. And it isn't like this dynArray[][]= 0?
    Code:
    if(search(Array,ID,row,r,c,lab))

    It still got the syntax error in no matching function call
    Last edited by erictu; 03-30-2012 at 07:32 PM.

  8. #23
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Move search function declaration above the logout declaration.

  9. #24
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    It still doesn't work. The syntax error said non-value assismentT_T

  10. #25
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    OH, in that case:
    Move the search function declaration above the logout declaration. Then post the updated code and actual copy-and-paste of the error message.

    I see lots of new in your program, but no delete. Figure out how and when you are going to delete stuff and you will solve more of your problem.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  11. #26
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    Here is the new code with the non-lvalue in assignment
    Code:
    #include <iostream>#include <cstdlib>
    
    
    using namespace std;
    void Displaylab(int *lab,int size)
    {
        int i;
         for(i = 0; i < size; i++)
         lab[i] = 0;
         lab[i] = -1;
         return;
    }
    int **dynArray(int row, int cols)
    {
        int **myPtr;
        int lab[4];
        myPtr = new int *[row];
        for(int i = 0; i < row; i++)
        myPtr[i] = new int[lab[i]];
        int i = 0;
        int size;
        if(myPtr[i] == 0)
        cout<<"empty";
        return myPtr;   
    }
    
    
    void getinput(int ID,int &Station,int &labnumb)
    {
         cout<<"Enter your ID number: "<<endl;
         cin>>ID;
          cout<<"Enter your station number: "<<endl;
         cin>>Station;
          cout<<"Enter your lab number: "<<endl;
         cin>>labnumb;
         return;  
    }
    void login(int **Array,int ID,int &Station,int &labnumb)
    {
         getinput(ID,Station,labnumb);
         Array[labnumb-1][Station-1] = ID;  
         return;
         
    }
    bool search(int **Array,int ID,int row,int &r,int &c,int lab[])
    {
         cout<<"Enter user ID to check: "<<endl;
         cin>>ID;
         bool found = false;
         for(int i = 0; i < row;i++)
         for(int j = 0; j < lab[i];j++)
         if(ID == Array[i][j])
         {
          found = true;
          r = i;
          c = j;
          
          }
         return found;
    }     
    void logout(int **Array,int ID,int row,int lab[])
    {
         int r,c;
         if(search(Array,ID,row,r,c,lab))
         dynArray(r,c) = 0;
         cout<< "You have been logged out."<<endl;
        return;
    }
    
    
    void Menu(int **Array,int ID,int &Station,int &labnumb,int row,int &r,int &c,int lab[])
    {
         int choice;
         cout<<"Enter 1 for login, 2 for search,3 for exit. "<<endl;
         cin>>choice;
         if(choice == 1)
             login(Array,ID,Station,labnumb);
         if(choice == 2)
             search(Array,ID,row,r,c,lab);
         if(choice == 3)
             exit(0);
         return;
    }
    
    
    int main()
    {
        int lab[4];
        lab[0] = 5;
        lab[1] = 6;
        lab[2] = 4;
        lab[3] = 3;
        int **labmain;
         labmain = new int*[4];
        for(int i = 0; i <4 ; i++)
        {
                *(labmain + i) = new int;
        }
        labmain = dynArray(4,7);
        int ID,Station,row,r,c,labnumb;
         Menu(labmain,ID,Station,labnumb,row,r,c,lab);
          system("PAUSE");
          return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. User login history - bash
    By garcy in forum Linux Programming
    Replies: 3
    Last Post: 05-17-2011, 10:23 AM
  2. Replies: 8
    Last Post: 12-08-2009, 12:55 PM
  3. Replies: 5
    Last Post: 05-06-2004, 09:14 AM
  4. Tracking Devices, GPS and etc.
    By Liger86 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 05-14-2003, 05:12 AM
  5. creating a user login system for web pages
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-04-2002, 11:02 PM