This forum is in archive mode. You will not be able to post new content.

Author Topic: [C++]Variable trouble help!  (Read 3298 times)

0 Members and 1 Guest are viewing this topic.

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
[C++]Variable trouble help!
« on: April 06, 2011, 02:24:49 AM »
Quote
#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
« Last Edit: April 13, 2011, 05:52:56 AM by gh0st »

Offline Satan911

  • VIP
  • Knight
  • *
  • Posts: 289
  • Cookies: 25
  • Retired god/admin
    • View Profile
Re: Variable trouble help!
« Reply #1 on: April 06, 2011, 02:38:01 AM »
Code: [Select]
void clockfunction(int minutes, int hours)
Satan911
Evilzone Network Administrator

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
Re: Variable trouble help!
« Reply #2 on: 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)'
« Last Edit: April 06, 2011, 04:19:49 AM by gh0st »

Offline Satan911

  • VIP
  • Knight
  • *
  • Posts: 289
  • Cookies: 25
  • Retired god/admin
    • View Profile
Re: Variable trouble help!
« Reply #3 on: April 06, 2011, 04:34:33 AM »
Check the function declaration. You declared it as an int with 1 argument.
Satan911
Evilzone Network Administrator

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
Re: Variable trouble help!
« Reply #4 on: 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

so it should look like this

Code: [Select]
#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




Offline FuyuKitsune

  • Knight
  • **
  • Posts: 292
  • Cookies: 21
    • View Profile
Re: Variable trouble help!
« Reply #5 on: April 06, 2011, 05:03:09 AM »
That error is because you have 2 functions with the same name "clockfunction"

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
Re: Variable trouble help!
« Reply #6 on: 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

Offline Satan911

  • VIP
  • Knight
  • *
  • Posts: 289
  • Cookies: 25
  • Retired god/admin
    • View Profile
Re: Variable trouble help!
« Reply #7 on: April 06, 2011, 05:53:25 AM »
I'm pretty sure it'll work if line 6 is:
Code: [Select]
void clockfunction(int hours, int minutes);
Satan911
Evilzone Network Administrator

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
Re: Variable trouble help!
« Reply #8 on: 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:

Code: [Select]
#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


 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.