Results 1 to 3 of 3

Thread: Question about functions in C++

  1. #1

    Question about functions in C++

    Ok, after learning a bit more C++, I've decided to take another shot at the stresser program.



    But, I've got two basic questions abou functions...


    When declaring a function with a data type, do all arguments with data types have to be the same type as the function decleration? Or can they vary?

    And also, can I have multiple functions in a single program? If so, how would I set them up?
    Tell me if you think I\'m spamming or doing something stupid, please.

  2. #2
    Member
    Join Date
    Feb 2003
    Posts
    78
    Ok, Im not sure what a stresser program is...but I think I can help.

    When declaring a data type, the arguments can vary. So you could have a void function with three int passed to it. Or a float function with three int passed to it. Declaring the type of fuction tells the computer which data type you will return. So if you do have a float function with three int passed to it, just make sure you are returning a float and not an int, or else it will give you an error.

    Yes, you can have as many fuctions as you want. That is what is great about functions, they make your code neat and organized.

    Code:
    //Test
    #include<iostream>
    
    using namespace std;
    
    void this_function(int, int);
    float that_function(int, int);
    
    int main()
    {
        float x;
        this_function(1,2);
        x = that_function(3,4);
        cout<<x<<endl;
        return 0;    
    }
    
    void this_function(int a, int b)
    {
        int x;
        x = a + b;
        cout<<x<<endl;
        return;    
    }
    
    float that_function(int a, int b)
    {
        float x;
        x = (a+b)*2;
        return x;    
    }
    I hope that helps.

    -Ep
    01001001001000000100110001101111011101100110010100100000010000100110010101110100011101000111100100100001

  3. #3
    You just answered my questions fully and in a way I can actually undersand . Thanks!




    COOKIE FOR YOU! Cookie --> @



    EDIT: And a Stresser program is something like Prime95 or Sandra. I'm coding a simple one along the lines of Sandra's method, which is floating point arithmetic. Right now it's command line based, but I hope to get a GUI on it when I learn more C++.
    Tell me if you think I\'m spamming or doing something stupid, please.

Posting Permissions

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