What is the problem?

This is a discussion on What is the problem? within the C++ Programming forums, part of the General Programming Boards category; The following code does not run. What is the problem? It returns message () expected. Code: # include<iostream.h> # include<conio.h> ...

  1. #1
    Registered User planet_abhi's Avatar
    Join Date
    Oct 2002
    Posts
    92

    Question What is the problem?

    The following code does not run.
    What is the problem?
    It returns message () expected.
    Code:
    # include<iostream.h>
    # include<conio.h>
    # include<stdio.h>
    class person
    {
    private:
    int age;
    char name[20];
    public:
    void getdata();
    void putdata();
    };
    void person::getdata()
    {
    cout<<"Enter the name";
    cin>>name;
    cout<<"Enter age";
    cin>>age;
    }
    void person:: putdata()
    {
    cout<<"\nName  :"<<name<<"\n";
    cout<<"Age   :"<<age;
    }
    
    int main()
    {
    person a;
    void  pline(char ch '#',int i=40);
    clrscr();
    a.getdata();
    pline();
    a.putdata();
    return(0);
    }
    void pline(char ch,int i)
    {
    for(i=0;i<=40;i++)
    printf("%c",ch);
    }
    AbHHinaay

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    It seems you're having confusion with your pline() function:

    1) Your pline() function has no prototype.
    Code:
    void pline(char ch,int i); //Put this above main() !
    2) Your first call to your pline() function does not have valid agruments:

    Why do you have
    Code:
    void  pline(char ch '#',int i=40); //We don't like this
    in main()? When you're calling a function, don't declare the arguments within the function call. Instead, pass it like:
    Code:
    pline('#',40); //We like this
    3) Your second call to the pline() function has no arguments:
    Code:
    pline(); //invalid
    The pline() function takes two arguments, so you'll need to pass to it two arguments.

    By the way, I *think* you meant:
    Code:
    void pline(char ch,int i)
    {
         for(int x=0;x<=i;x++) //loop 40 times (or whatever number gets passed to it)
         printf("%c",ch);
    }
    Last edited by funkydude9; 08-09-2003 at 12:10 AM.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>1) Your pline() function has no prototype.
    His method is perfectly valid. You are allowed to prototype inside of a function.

    void pline(char ch = '#',int i=40);
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Originally posted by XSquared
    >>1) Your pline() function has no prototype.
    His method is perfectly valid. You are allowed to prototype inside of a function.

    void pline(char ch = '#',int i=40);
    Well, it may be valid, but in a large project you would have a hard time finding your first prototype again once you have to change the implementation

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    Re: What is the problem?

    Yup, you just forgot the '=' sign :-)

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    You are allowed to prototype inside of a function.
    Wow, my bad. I've just never seen that before. I thought he was just confused about functions...lol.
    Last edited by funkydude9; 08-09-2003 at 10:14 AM.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    The for-loop will loop once more than expected.
    That is, if I pass 20 it will loop 21 times, because of the =0, <= combination.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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