I am slowly understanding functions, but I can't completely wrap my head around it yet. What is the purpose of function with nothing in the parentheses? Like this something(). Also, is there a way to write a function and then have it output what is going on in that function?

void findHighest(int score1, int score2, int score3, int score4, int score5, int score6)
{
	int highest;

if (score1>= score2 && score1>= score3 && score1>= score4 && score1>=score5 && score1>= score6)
	highest = score1;
else if (score2 >= score3 && score2>= score4 && score2>= score5 && score2>= score6)
	highest = score2;
else if (score3>= score4 && score3>= score5 && score3>= score6)
	highest = score3;
else if (score4>= score5 && score5>= score6)
    highest = score4;
else if (score5>= score6)
	highest = score5;
else
	highest = score6;

}

Can I see what i'm getting for highest?

The only reason i have came across for a function with nothing sent to it and no return is output to the console.
Google cout.

What is the purpose of function with nothing in the parentheses? Like this something()

To do something where you need to provide no more input. The most obvious is a default constructor. Any time you create an instance of an object more advanced that the most basic of plain data, such a function is called (even if you didn't write it, it was created for you and run when you create the object). Other common ones are to get a value returned. For example, imagine you had a class that stored values for you. How would you get a value from it? Like this:

object.getValue();

There is a literal infinity of reasons one might have a function that takes no input parameters.

Also, is there a way to write a function and then have it output what is going on in that function?

int someFunction()
{
  cout << "I'm your function, doing some things!" << endl;
  int y = 2+3;
  cout << "I'm your function, doing some other things!" << endl;
  return y;
}

What is the purpose of function with nothing in the parentheses? Like this something().

Many times the function is for input, and it simply returns the data entered (getchar() for example)
Other times it can load your class data from values saved on disk, for initialization or returning to where you left off in a game (more input)
Maybe it will initialize some hardware so you can access it

Lots of reasons.

Also, is there a way to write a function and then have it output what is going on in that function?

Use cout as suggested.

Also, is there a way to write a function and then have it output what is going on in that function?

Now, I have to ask: just what do you mean by 'have it output'? Where do you want to results sent - to the console, to the calling function, to somewhere else?

If you want to output to the console, then as said by others earlier, you want to use the standard output ( cout ) to print the result.

If, on the other hand, you want to return the results to the function which called it, then you want to do two things: change the return value from void to the type of the return value ( int in this case), and use the return operator followed by the value you want to return.

Having nothing in the brackets comes in useful if you wish to draw something directly to the screen and no input is needed. It allows you to write an algorithm that steps through a process and then call it as many times as you want.

There maybe several different occasions in a program when you may want to run the algorithm in certain condtion. Without the function you would have to duplicate the code. With one function simply call it multiple times.

You can do something such as double getNum() then return num. To return a value so it can be used outside of its class/function. This can only return a single value usally if you want to return multiple values you usually store the variables in an array, and access the array when needed.

Hope this helps

P.S sorry for any spelling mistakes im on a mobile device currently

Now, I have to ask: just what do you mean by 'have it output'?

The message " ... have it output [B]what is going on[/B] in that function? " is to me clear. He wants to 'debug' the function and make sure the proper values are being generated. Am I mistaken?

That had been my own impression, true, but I felt it best to make sure all possible cases were covered. If I have overstepped or misled in any way, I certainly apologize.

The message " ... have it output [B]what is going on[/B] in that function? " is to me clear. He wants to 'debug' the function and make sure the proper values are being generated. Am I mistaken?

you are correct.

Wow. It's the simple things that drive me crazy. cout is what I was looking for. Thanks guys.

It's the simple things that drive us ALL crazy. "You mean all I had to do is...???"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.