Passing two values to a type void function C++

nothingasis

In Runtime
Messages
198
Location
CA
So I'm being told in this problem to, pass two values to a type void function that displays the two values through the main() function.

#include <iostream>

void display(int);


int main ()
{
using namespace std;
cout << "Enter the number of hours: ";
int hours;
cin >> hours;
int minutes;
cout << "Enter the number of minutes: ";
cin >> minutes;
display(hours, minutes);
system ("pause");
return 0;
} // Closes off the function

void display(int hours, int minutes)
{
using namespace std;
cout <<"Time: " << hours << ":" <<minutes <<endl; display()
}

It gives me the error, "display function does not take 2 arguments.

I understand that, that is true but I'm not sure what other approach i can take with this. I'm still really new to this so, if possible I'd like to stick to the basics with no advance way of doing this that may make it a lot easier.

So, tell me programmers what am I doing wrong here and what should I do about it? Please and thank you!
 
At the top, before the main function,

Code:
void display(int);
needs to be
Code:
void display(int hours, minutes);

Alternatively, move this function
Code:
void display(int hours, int minutes)
{
using namespace std;
cout <<"Time: " << hours << ":" <<minutes <<endl; display()
}
to above the main function.
But you also need to remove the 'int' before 'minutes' in that function (I believe - might work fine with it but it's bad form).


The problem, I think, is that 'void display(int hours, minutes)' has not yet been initialised when it's called in the main function.
 
Last edited:
Worked perfectly! Thank you! And that actually makes a lot of sense. That the function hasn't been initialized yet hence the error in the main().
 
Glad I could be of help :) I'm very glad that helped, I was slightly not sure only having done some C++ for a uni project a month or so ago.
 
Back
Top Bottom