-
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);
-
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);
-
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>