EvilZone
Programming and Scripting => C - C++ => : gh0st April 06, 2011, 02:24:49 AM
-
#include <iostream>
#include <cmath>
using namespace std;
int clockfunction(int);
int main()
{
int hours;
int minutes;
cout << "enter the number of hours: ";
cin >> hours;
cout << endl;
cout << "enter the number of minutes: \n";
cin >> minutes;
cout << endl;
int time = clockfunction(hours,minutes);
cout << "time " << hours << ":" << minutes << endl;
system("pause");
return 0;
}
void clockfunction(int n)
{
cout << hours << ":" << minutes;
}
hello guys well as u can see I still trying to solve the problems of my C++ book and this is the last one of the first chapter :D
ok my trouble is that I just dont know how to use 2 variables into the user-definded function : "clockfunction(int)" .
awards: +1 of karma
-
void clockfunction(int minutes, int hours)
-
nope doesnt seem to work
6 C:\Documents and Settings\fernando\Escritorio\Untitled1.cpp too many arguments to function `void clockfunction(int)'
-
Check the function declaration. You declared it as an int with 1 argument.
-
well accoring to this page the function declaration should be like this:
http://bytes.com/topic/c/answers/547519-too-many-arguments-function (http://bytes.com/topic/c/answers/547519-too-many-arguments-function)
so it should look like this
#include <iostream>
#include <cmath>
using namespace std;
int clockfunction(int,int);
int main()
{
int hours;
int minutes;
cout << "enter the number of hours: ";
cin >> hours;
cout << endl;
cout << "enter the number of minutes: \n";
cin >> minutes;
cout << endl;
int time = clockfunction(hours,minutes);
cout << "time " << hours << ":" << minutes << endl;
system("pause");
return 0;
}
void clockfunction(int hours, int minutes)
{
cout << hours << ":" << minutes;
}
then I get
25 C:\Documents and Settings\fernando\Escritorio\Untitled1.cpp new declaration `void clockfunction(int, int)'
:P It should work Idk whats going on
-
That error is because you have 2 functions with the same name "clockfunction"
-
u mean the part where I write again the function well is not that Im declaring it again thats something named user- defined function I already posted something about that u can check them on C-C++ topics but thanx for the intention
-
I'm pretty sure it'll work if line 6 is:
void clockfunction(int hours, int minutes);
-
@Satan911: I did it then it dropped me an error and from it I fixed the source code and eneded like this:
#include <iostream>
#include <cmath>
using namespace std;
void clockfunction(int hours, int minutes);
int main()
{
int hours;
int minutes;
cout << "enter the number of hours: ";
cin >> hours;
cout << endl;
cout << "enter the number of minutes: \n";
cin >> minutes;
cout << endl;
clockfunction(hours,minutes);
system("pause");
return 0;
}
void clockfunction(int hours, int minutes)
{
cout << hours << ":" << minutes;
cout << endl;
}
ty again satan +1 of karma