Thread: Need a function

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    17

    Need a function

    How do i make a function that uses this statement:

    cout << "Enter 4 positive number: "<<endl;
    for( x = 0; x < north; x++)

    cin >> north;
    cin >> south;
    cin >> east;
    cin >> west;


    cout <<'*';

    I am not allowed to use assigment statements, only function calls. I don't know how to do that with a statement that isn't mathamatic. I know there is probably a better way to write the above statement, possibly using a loop. But i am really stuck on how to creat a function

    Anyone who can help, I would very much appreciate it.

  2. #2
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49
    Could you post the exact assignment.
    Ivan

  3. #3
    Unregistered
    Guest

    try this

    #include<iostream.h>

    int get_numbs(); //prototype


    int get_numbs() // the function
    {
    int x;
    int y = 5;
    static int array[4];


    cout << "Enter 4 positive number: "; //tell them what to do

    for( x=1; y > x; x++) // run this four times to get numbers
    {
    cout << "\n Enter number " << x << " ";
    cin >> array[x];
    }
    // print out the numbers to the screen
    cout << "\n\nNumber 1 Equals "
    << array[1] << " \nNumber 2 Equals "
    << array[2] << " \nNumber 3 Equals "
    << array[3] << " \nNumber 4 Equals "
    << array[4] << "\n\n\n";
    return 0; //done, go back to main

    }



    int main(void) // the main returns an int and has no arguments
    {
    get_numbs(); //call the function get_numbs()
    return 0; // send this to the OS, good bye
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM