Thread: Whats wrong?

  1. #1

    Angry Whats wrong?

    I have just started with C++ and I am just messing around with defining functions and cannot firgure it out. I am compiling this with VC++6 Introductory Edition, just to let you know.

    Code:
    #include <iostream>
    
    int munkey()
    {
         std::cout << "Munkey() was just ran\n";
         return 0;
    }
    
    int main()
    {
         munkey()
         std::cout << "Main() was just ran.";
         return 0;
    }
    Last edited by Munkey01; 12-23-2002 at 10:58 AM.

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: Whats wrong?

    Originally posted by Munkey01
    I have just started with C++ and I am just messing around with defining functions and cannot firgure it out. I am compiling this with VC++6 Introductory Edition, just to let you know.

    Code:
    #include <iostream>
    
    int munkey()
    {
         std::cout << "Munkey() was just ran\n";
         return 0;
    }
    
    int main()
    {
         std::cout << "Main() was just ran.";
         return0;
    }
    Do you have a question?

    What is your desired output?

    If you want to display "Munkey() was just ran" (should be run, but we're programmers, who needs grammar ), then you have to explicitly call the function. The only function that gets called at the start of your program is main.

    You'd have to change main to

    Code:
    int main()
    {
         munkey();
         std::cout << "Main() was just ran.";
         return 0;
    }
    in order to get the output you apparently want.

    Also note that you missed a space between "return" and "0"

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Would adding an << endl; there help? Doesn't endl flush stdout as well as provide a new line?

  4. #4
    Yea I noticed that I forgot to call munkey() and that I had left out the space between return and 0. Thats why i edited my post. But what I wanted to know is why do i get errors when i compile this?

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Shouldn't really matter here. The problem is that we don't really have a question. What is the desired output?

  6. #6
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Yea I noticed that I forgot to call munkey() and that I had left out the space between return and 0. Thats why i edited my post. But what I wanted to know is why do i get errors when i compile this?
    you need a semicolon after you call the function in main (refer to my previous post).

    Edit: Before we go any further, I've got a hunch.

    When you created a new project, did you select "win32 console application" or "win32 application."

    You want to select "win32 console application"
    Last edited by Polymorphic OOP; 12-23-2002 at 11:04 AM.

  7. #7
    I want my output to be:

    Munkey() was just ran.
    Main() was just ran.
    I didn't think you needed a semicolon after you call functions.

  8. #8
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Polymorphic OOP
    Edit: Before we go any further, I've got a hunch.

    When you created a new project, did you select "win32 console application" or "win32 application."

    You want to select "win32 console application"
    Didn't get the edit in on time, so I'm posting in case you missed it.

    I didn't think you needed a semicolon after you call functions.
    The semicolon isn't needed to call the function, it's to end the expression. Otherwise, when you compile it will think that the next line is a part of the same expression, which it isn't.

  9. #9
    Thanks guys. I finally got it working. It was just the semicolon after munkey().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM