help with functions (first time)

This is a discussion on help with functions (first time) within the C++ Programming forums, part of the General Programming Boards category; this is my first time using functions and i would like to know how i should pass the seconds and ...

  1. #1
    Unregistered
    Guest

    Angry help with functions (first time)

    this is my first time using functions and i would like to know how i should pass the seconds and minutes from the readtime function to the displaytime function?

    Code:
    #include <iostream.h>
    
    //------------------------------------------------------------------------------------------------
    int ReadTime(int Minutes, int Seconds) // dont see the purpose of this but the book im using says to have 2 parameter :|
    /* get seconds and time */
    {
    	cout<<"\tEnter minutes: ";
    	cin>>Minutes;
    	cout<<"\tEnter seconds: ";
    	cin>>Seconds;
    
    	return (Minutes, Seconds);
    }
    //------------------------------------------------------------------------------------------------
    void DisplayTime(int Minutes, int Seconds)
    /* display the time in hh:mm:ss form */
    {
    	int Hours=0;
    
    	while(Minutes>60)
    	{
    		
    		if (Minutes>=60)
    		{
    			Minutes=Minutes-60;
    			Hours++;
    		}
    
    		if (Seconds>=60)
    		{
    			Seconds=Seconds-60;
    			Minutes++;
    		}
    	}
    
    	cout<<Hours<<":";
    	
    	if(Minutes<10)
    	{
    		cout<<"0"<<Minutes<<":";
    	}
    
    	else if(Minutes>=10)
    	{
    		cout<<Minutes<<":";
    	}
    	
    	if(Seconds<10)
    	{
    		cout<<"0"<<Seconds;
    	}
    
    	else if(Seconds>=10)
    	{
    		cout<<Seconds;
    	}
    	
    	cout<<endl;
    }
    //------------------------------------------------------------------------------------------------
    int main()
    {
    	int Minutes=1,Seconds=1;
    	
    	cout<<"Enter a time:"<<endl;
    	ReadTime(Minutes, Seconds);
    	cout<<"Your time was ";
    	DisplayTime(Minutes, Seconds);
    
    	return (0);
    }

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    What book are you reading?? I do not think that you can have a function return more than one value unless you put it into a struct. or class.

  3. #3
    Unregistered
    Guest
    well here is the question from Lawrencevill Press "Programming in c++"

    a). write two utility functions, reatime() and displaytime(), that handle reading and writting of times. Test the function with the code:

    {
    int min,sec;
    cout<<"Enter a time: ";
    ReadTime(min,sec);
    cout<<"Your time was: ";
    DisplayTime(min,sec );
    }

    The program out put should look like

    Enter a time:

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    pass-by-reference

    void ReadTime(int &Minutes, int &Seconds)

  5. #5
    Unregistered
    Guest
    Originally posted by Syneris
    pass-by-reference

    void ReadTime(int &Minutes, int &Seconds)
    hey dude thx i had forgotten about that one cheers!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  2. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  3. Military Time Functions
    By BB18 in forum C Programming
    Replies: 6
    Last Post: 10-10-2004, 02:57 PM
  4. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 02:21 PM
  5. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21