Using struct in function. Allows me to declare, but wont let me call.

This is a discussion on Using struct in function. Allows me to declare, but wont let me call. within the C++ Programming forums, part of the General Programming Boards category; Here is my code.. Code: #include <iostream> #include <stdlib.h> int bill(struct info(int id, int pass)); struct info { int id; ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    28

    Using struct in function. Allows me to declare, but wont let me call.

    Here is my code..

    Code:
     #include <iostream>
    #include <stdlib.h>
    
    int bill(struct info(int id, int pass));
    struct info
     { 
      int id;
      int pass;
     };
    
    int main(int argc, char *argv[])
    { 
       
      system("PAUSE");	
      return 0;
    }
    
    int bill(struct info(int id, int pass))
     {
     
      info bill;
       {
        bill.id;
        bill.pass;
       }
       for(bill.id=0; bill.id != 123; bill.id++) 
        {cout<<"What is your 3 digit id?\n";
         cin>>bill.id;
         
          if(bill.id==3)
           { break;
             return 0;
           }
           
          if(bill.id==123)
            {
             cout<<"ID is correct.";
            }
       
          if(bill.id!=123)
            {
             cout<<"ID is incorrect. Please try again";
            }
        }
        for(bill.pass=0; bill.pass != 321; bill.pass++)
         {
          cout<<"What is your 3 digit password?\n";
          cin>>bill.pass;
           if(bill.pass==3)
            { 
             break;
             return 0;
            }
        
           if(bill.pass==321)
            {
             cout<<"Pass is correct";
            }
         
           if(bill.pass!=321)
            {
             cout<<"Pass is incorrect";
            }
         }
     }
    I want it to ask for the id and password of a user. Declare the struct inside the function but it wont let me call the function with the struct inside of main. Please help.
    ~matt~

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    >> int bill(struct info(int id, int pass));

    Try :

    int bill(struct info i);

    'i' would represent the struct in the function.

    If you want to be able to use the struct without explicitly using the keyword "struct", then typedef the struct like this:
    Code:
    typedef struct{
    //..
    //..
    }info;

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    Can you make this alittle bit more clear for me...im really new to struct, and programming in general..
    ~matt~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 07:54 PM
  3. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM

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