parameters

This is a discussion on parameters within the C++ Programming forums, part of the General Programming Boards category; Hi, I have something wrong with some code that I'm trying to write. The error message said "function does not ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    34

    parameters

    Hi,
    I have something wrong with some code that I'm trying to write.
    The error message said "function does not take 1 parameters"
    I'm using Visual C++ 6.0 and the MSDN Library states that I'm calling with incorrect number of parameters. The message occurs on the second line in the Switch case #2. It has something to do with the Sec_To_HMSTime prototype. (I think) I would appreciate it greatly if someone could help me locate the problem. Another set of eyes usually always helps! Thanks, mcorn.
    Code:
    #include<iostream.h>
    #include<stdlib.h>
    
    void GetTime(int*,int*,int*);
    int CalcSeconds(int,int,int);
    bool CheckInput(int*,int*);  //new function protocol
    void GetSeconds(int*);     // "      "        "
    int Sec_To_HMSTime(int,int*,int*,int*); //"      "        "
    
    int main()
    {
    
    	int hr,min,sec,seconds;
    	//char another;
    	int total_sec, tot_sec, choice;
    
    	cout<<"\n\nWelcome to a time-conversion program! \n\n";
    
    
    	do
    	{
    
    		cout<<"\nPlease pick a choice:"
    			<<"\n1) Convert H:M:S to seconds."
    			<<"\n2) Convert seconds to H:M:S."
    			<<"\n3) Exit." << endl << endl;
    		cin>>choice;
    
    		switch(choice)
    		{ 
    			
    		  case 1:
    		    GetTime(&hr,&min,&sec);
    		    total_sec=CalcSeconds(hr,min,sec);
    
    		    cout<<"\n\nYou Entered " << total_sec << " seconds ";
    		    cout<<"\nIt is " << total_sec << " seconds "<<endl;
                break;
    
    		  case 2:
    			  GetSeconds(&seconds);
    			  tot_sec=Sec_To_HMSTime(seconds);
    
    			  cout<<"\nYou Entered" << tot_sec;
    			  cout<<"\nIt is"<<hr<<":"<<min<<":"<<sec;
    			  break;
    		  case 3:
    			  cout<<"\nTest3"<< endl << endl;
    			  break;
    		  
    		 
    		  default:
    		      cout<<"\nThat's not a valid choice!";
    		}
    
    	}while(choice !=3);
    	
    	cout<<"\nBye!"<<endl<<endl;
    
    
    	
    	
    	
    
    	cout<<"\nThanks for playing! \n";
    	return 0;
    }
    
    void GetTime(int *h_ptr,int *m_ptr, int *s_ptr)
    {
    
    	int ask_them_again = 1;
    	char colon;
    
    	while(ask_them_again == 1)
    	{
    
    		cout<< "\n Please enter the time in hours minutes seconds "
    			<< "\n Such as 4:15:34 (Note: Minutes and Seconds < 60 ) \n\n==>";
    		cin>> *h_ptr >> colon >> *m_ptr >> colon >> *s_ptr;
    
    		ask_them_again = 0;
    		if(*m_ptr > 59 || *s_ptr > 59)
    		{
    
    			cout << "\n WHOA!!! Invalid Time!!! ";
    			ask_them_again = 1;
    		}
    	}
    }
    
    int CalcSeconds(int hr, int min, int sec)
    {
    
    	int total_sec;
    	total_sec = hr*3600 + min*60 + sec;
    	return total_sec;
    }
    
    int Sec_To_HMSTime(int h_m_s, int *hr, int *min, int *sec)
    {
    
    	int total_secs;
    	*hr = h_m_s/3600;
    	h_m_s = h_m_s%3600;
    	*min = h_m_s/60;
    	*sec = h_m_s%60;
    	return total_secs;
    }
    tot_sec=Sec_To_HMSTime(seconds);

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    It means exactly what it says. You've declared the function as -

    int Sec_To_HMSTime(int,int*,int*,int*);

    You need to pass in the addresses of your integers hr,min,sec as the further three parameters. So it'd look something like -

    tot_sec=Sec_To_HMSTime(seconds, &hr,&min,&sec);
    Joe

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    If you say you are going to pass (int,*int,*int,*int) and not giving default arguments, you cant simply get away with just passing a single int

    Try this;
    Code:
    #include<iostream.h>
    #include<stdlib.h>
    
    void GetTime(int*,int*,int*);
    int CalcSeconds(int,int,int);
    bool CheckInput(int*,int*);  //new function protocol
    void GetSeconds(int*);     // "      "        "
    void Sec_To_HMSTime(int,int*,int*,int*); //"      "        "
    
    int main()
    {
    
    	int hr,min,sec,seconds;
    	//char another;
    	int total_sec, choice;
    
    	cout << endl << "Welcome to a time-conversion program!" << endl << endl;
    
    
    	do{
    
    		cout << endl << "Please pick a choice:"
    		<< endl << "1) Convert H:M:S to seconds."
    		<< endl << "2) Convert seconds to H:M:S."
    		<< endl << "3) Exit." << endl << endl;
    		cin>>choice;
    
    		switch(choice){
    		case 1:
    			GetTime(&hr,&min,&sec);
    			total_sec=CalcSeconds(hr,min,sec);
    
    			cout << endl << "You Entered " << hr << ":" << min << ":" << sec;
    			cout << endl << "It is " << total_sec << " seconds "<< endl;
    			break;
    
    		case 2:
    		    GetSeconds(&seconds);
    		    Sec_To_HMSTime(seconds,&hr,&min,&sec);
     
    		    cout << endl << "You Entered " << seconds;
    		    cout << endl << "It is "<< hr <<":"<< min << ":" << sec ;
    		    break;
    		case 3:
    		    cout << endl << "Test3"<< endl << endl;
    		    break;
     
    
    		default:
    		    cout<<"\nThat's not a valid choice!";
    		}
    
    	}while(choice !=3);
    
    	cout << endl << "Bye!" << endl << endl;
    	cout << endl << "Thanks for playing!"<< endl;
    	return 0;
    }
    
    void GetTime(int *h_ptr,int *m_ptr, int *s_ptr)
    {
    	char colon;
    
    	while(1)
    	{
    
    		cout << endl << "Please enter the time in hours minutes seconds "
    		<< endl <<"Such as 4:15:34 (Note: Minutes and Seconds < 60 )"
    		<< endl << endl << "==>";
    		cin >> *h_ptr >> colon >> *m_ptr >> colon >> *s_ptr;
    
    		
    		if(*m_ptr > 59 || *s_ptr > 59)
    		{
    
    			cout << endl << "WHOA!!! Invalid Time!!! ";
    		}
    		else break;
    	}
    }
    
    void GetSeconds(int *sec)
    {
    		cout<< endl << "Please enter the number of seconds" << endl;
    		
    		cin >> *sec ;
    
    }
    
    int CalcSeconds(int hr, int min, int sec)
    {
    	return hr*3600 + min*60 + sec;
    }
    
    void Sec_To_HMSTime(int h_m_s, int *hr, int *min, int *sec)
    {
    
    	*hr = h_m_s / 3600;
    	h_m_s = h_m_s % 3600;
    	*min = h_m_s / 60;
    	h_m_s = h_m_s % 60;
    	*sec = h_m_s;
    }
    <edit>..beaten to it ! </edit>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parameters quick Question
    By lifeis2evil in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2007, 11:12 PM
  2. function with variable number of parameters
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 04:35 PM
  3. Additional parameters for operator delete
    By darksaidin in forum C++ Programming
    Replies: 0
    Last Post: 09-21-2003, 12:46 PM
  4. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  5. command-line parameters.
    By Tombear in forum C Programming
    Replies: 2
    Last Post: 10-28-2001, 08:40 AM

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