Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Beginner Function Calling Question

  1. Aug 29, 2010 #1
    Below is a sample code. My professor starts code and we have to finish the code. Below is not the assignment but a sample I have written up to help my question. I have two .cpp files one named main the other named func1. Within func1 I have a function called matheq. I was just wondering if there was some way to have my main.cpp print out the matheq numbers in the parentheses? Or do I have to redefine them in my second func2.cpp file?

    I added a cout statement trying to show what I am trying to do, I know it is wrong but I just wanted to show some basic code to back up my statement.

    Thanks again for your help!

    -Mike
    Code (Text):

    #include<iostream>
    void matheq(double a,double b,double c);
    using namespace std;
    int main()
    {

    matheq(1.0,3.3,2.1);
    matheq(1.0,3.3,5.1);
    matheq(1.0,3.3,0.0);

    cout << "matheq(a) << endl;


    }

     
     
  2. jcsd
  3. Aug 29, 2010 #2

    Mark44

    Staff: Mentor

    Before calling matheq(), you could have an output statement like this:
    Code (Text):

    cout << "First arg: 1.0" << " Second arg: 3.3" << " Third arg: 2.1" << endl.
    matheq(1.0, 3.3, 2.1);
    // and so on
     
    Is that what you're asking?
     
  4. Aug 29, 2010 #3
    Yeah that is exactly what I was looking for. However, I think I have found my error. I believe I need to do my cout statements inside of my matheq function. I did that and it worked.

    Thank you though Mark for responding!!
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook




Loading...
Similar Threads for Beginner Function Calling Date
C/++/# Is Pass-by-Reference part of a Function Signature? Mar 2, 2018
Fortran Beginner and a makefile file Aug 16, 2017
Python Which of these codes do you think is the simplest Nov 10, 2016
Python Beginner coding exercise confusion Oct 1, 2016
Fortran Fortran question (beginner) Oct 28, 2015