Homework Problem from C++ Primer Book

I am having trouble figuring this one out. The question from the book is the comment in the beginning. Please let me know if you see anything wrong. The compiler I am using (Dev-C++) tells me "In function 'int main()': no matching function for call to 'time(int&, int&)' candidates are: time_t time(time_t*) void time(int)."

// Write a program that asks the user to enter an hour value and a minute value. The main function should then pass these two values to a type void function that displays the two values in the 00:00 format

#include <iostream>
using namespace std;
void time(int);

int main()

{
int hour;
int minute;
cout << "Please enter number of hours: ";
cin >> hour;
cout << endl;
cout << "Please enter number of minutes: ";
cin >> minute;
cout << endl;
time(hour, minute);
cin.get();
cin.get();
return 0;
}

void time(int hour, int minute)

{
cout << hour << ":" << minute;
}
you declare your time function as void time(int); (only one parameter), but you implement void time(int,int); (two parameters)
The issue you have with your program is a very minor one, probably just an oversight. You only allowed void time(int) to take only 1 argument instead of 2 due to you having time(int hour,int min) having 2 =).

#include <iostream>
using namespace std;
void time(int,int); //this is where the error was now corrected
int main()

{
int hour;
int minute;
cout << "Please enter number of hours: ";
cin >> hour;
cout << endl;
cout << "Please enter number of minutes: ";
cin >> minute;
cout << endl;
time(hour, minute);
cin.get();
cin.get();
return 0;
}

void time(int hour, int minute)

{
cout << hour << ":" << minute;
}
Topic archived. No new replies allowed.