EvilZone

Programming and Scripting => C - C++ => : gh0st April 06, 2011, 02:24:49 AM

: [C++]Variable trouble help!
: 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
: Re: Variable trouble help!
: Satan911 April 06, 2011, 02:38:01 AM
:
void clockfunction(int minutes, int hours)
: Re: Variable trouble help!
: gh0st April 06, 2011, 04:17:33 AM
nope doesnt seem to work

6 C:\Documents and Settings\fernando\Escritorio\Untitled1.cpp too many arguments to function `void clockfunction(int)'
: Re: Variable trouble help!
: Satan911 April 06, 2011, 04:34:33 AM
Check the function declaration. You declared it as an int with 1 argument.
: Re: Variable trouble help!
: gh0st April 06, 2011, 04:52:19 AM
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



: Re: Variable trouble help!
: FuyuKitsune April 06, 2011, 05:03:09 AM
That error is because you have 2 functions with the same name "clockfunction"
: Re: Variable trouble help!
: gh0st April 06, 2011, 05:39:27 AM
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
: Re: Variable trouble help!
: Satan911 April 06, 2011, 05:53:25 AM
I'm pretty sure it'll work if line 6 is:
:
void clockfunction(int hours, int minutes);
: Re: Variable trouble help!
: gh0st April 06, 2011, 06:07:33 AM
@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