Beginner Function Calling Question

In summary, the conversation is about a code sample where the main.cpp file needs to print out the numbers in parentheses from the matheq function in the func1.cpp file. The person asking the question is trying to use a cout statement in the main.cpp file, but realizes they need to do it inside the matheq function. The conversation ends with a thank you to Mark for responding.
  • #1
chronie
23
0
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:
#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;}
 
Technology news on Phys.org
  • #2
Before calling matheq(), you could have an output statement like this:
Code:
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?
 
  • #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!
 

1. What is a function call?

A function call is when a program or code requests a specific function to be executed or performed.

2. How do you call a function in a program?

To call a function in a program, you need to use the function's name followed by parentheses, which may or may not contain any arguments or parameters.

3. What is the purpose of a function call?

The purpose of a function call is to execute a specific set of instructions or operations that have been defined within the function. This allows for code to be more organized, reusable, and efficient.

4. What is the difference between a function call and a function definition?

A function call is when a function is actually executed or run in a program, while a function definition is when the function is created and its instructions or operations are defined.

5. Can you have multiple function calls within a program?

Yes, you can have multiple function calls within a program. In fact, using multiple function calls is a common practice in programming to perform different tasks and improve code efficiency.

Similar threads

  • Programming and Computer Science
Replies
6
Views
901
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
2
Replies
39
Views
3K
  • Programming and Computer Science
Replies
3
Views
721
  • Programming and Computer Science
Replies
4
Views
777
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
1
Views
984
Back
Top