Beginner Function Calling Question

  • Thread starter Thread starter chronie
  • Start date Start date
  • Tags Tags
    Beginner Function
AI Thread Summary
The discussion revolves around a coding question where the user, Mike, seeks assistance on how to print values passed to a function from a separate .cpp file. He initially inquires whether he needs to redefine the parameters in another file or if there's a way to print them directly from the main file. Mike shares a sample code snippet and expresses confusion about how to display the arguments used in the function call. After receiving feedback, he realizes that incorporating the cout statements within the matheq function itself is the correct approach, which ultimately resolves his issue. The exchange highlights the importance of understanding function scope and output in C++ programming.
chronie
Messages
23
Reaction score
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
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?
 
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!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top