Closed Thread
Results 1 to 4 of 4

Thread: Multiple functions in a C++ program

  1. #1
    Join Date
    Oct 2008
    Location
    San Diego
    Posts
    629
    Rep Power
    19

    Multiple functions in a C++ program

    This is my first day of C++ and I was wondering how to get multiple functions in a C++ program. Any help would be appreciated. Here is my source.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        char number;
        cout << "Please input a value\n"; 
        cin >> number;
        cout << " You selected: " << number; 
        second(); // This should work in a C program, how do I do it in C++
        system("PAUSE");
        return 0;
    }
          
    int second() // This is where I run into problems
    {
        char number;
        cout << "Please select another value...";
        cin >> number;
        cout << "You selected: " << number;
    }
    Thanks
    Last edited by nicckk; 01-22-2011 at 10:12 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Multiple functions in a C++ program

    You have to declare second() before you can call it.
    Code:
    // Value selector
    // Nick Dichev 2009
    
    #include <iostream>
    using namespace std;
    
    int second() ;
    int main()
    {
        char number;
        cout << "Please input a value\n"; 
        cin >> number;
        cout << " You selected: " << number; 
        second(); // This should work in a C program, how do I do it in C++
        system("PAUSE");
        return 0;
    }
          
    int second() // This is where I run into problems
    {
        char number;
        cout << "Please select another value...";
        cin >> number;
        cout << "You selected: " << number;
    }
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Oct 2008
    Location
    San Diego
    Posts
    629
    Rep Power
    19

    Re: Multiple functions in a C++ program

    Thanks Winged, that worked. But the compiler then told me I needed a semi-colon before the int main(). I plugged it in and it worked fine. Can you describe why? I thought that a semi-colon ended a line of code?

    Thanks

  5. #4
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Multiple functions in a C++ program

    Code:
    int second();
    declares a function, and must end with a semi-colon, just like any other declaration (such as int
    Code:
    i;
    ).
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 09-06-2011, 01:46 AM
  2. Multiple Return Types in C++ Functions?
    By shezarkh in forum C and C++
    Replies: 2
    Last Post: 08-09-2011, 08:12 PM
  3. Calling multiple functions in a single line
    By fazlerocks in forum C and C++
    Replies: 4
    Last Post: 01-17-2011, 06:03 PM
  4. Program 5 Functions
    By bgm mcmuffin in forum C and C++
    Replies: 23
    Last Post: 10-12-2010, 10:05 PM
  5. Excel Macros: program to run multiple
    By GNR23 in forum Visual Basic Programming
    Replies: 0
    Last Post: 07-08-2009, 06:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts