Problems with function parameter...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 23
Reputation: gopi17 is an unknown quantity at this point 
Solved Threads: 0
gopi17 gopi17 is offline Offline
Newbie Poster

Problems with function parameter...

 
0
  #1
Aug 7th, 2009
I'm juz wondering how do I send a single value to a 8-parameter function...
  1. void enterdata1(int &row1col2)
  2. {
  3. cout<<"Please enter the number for Row 1-Columm 2"<<endl;
  4. cin>>row1col2;
  5. if(row1col2 != 1 && row1col2 != 2&& row1col2 != 3 && row1col2 != 4)
  6. {
  7. cout<<"Please enter the correct number (Which is between 1-4)"<<endl;
  8. cin>>row1col2;
  9. }
  10. displaydata(row1col2);
  11. }
  12.  
  13. void displaydata( int &row1col1,int &row1col2,int &row1col3,int &row1col4,int &row2col1,
  14. int &row2col2,int &row2col3,int &row2col4,int &row3col1,int &row3col2,
  15. int &row3col3,int &row3col4,int &row4col1,int &row4col2,int &row4col3,
  16. int &row4col4)
  17. {
  18. cout<<" |-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|"<<endl;
  19. cout<<" | "<<row1col1<<" | "<<row1col2<<" | "<<row1col3<<" | "<<row1col4<<" |"<<endl;
  20. cout<<" |-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|"<<endl;
  21. cout<<" | "<<row2col1<<" | "<<row2col2<<" | "<<row2col3<<" | "<<row2col4<<" |"<<endl;
  22. cout<<" |-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|"<<endl;
  23. cout<<" | "<<row3col1<<" | "<<row3col2<<" | "<<row3col3<<" | "<<row3col4<<" |"<<endl;
  24. cout<<" |-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|"<<endl;
  25. cout<<" | "<<row4col1<<" | "<<row4col2<<" | "<<row4col3<<" | "<<row4col4<<" |"<<endl;
  26. cout<<" |-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|-"<<"-"<<"-|"<<endl;
  27.  
  28. system("pause");
  29. }

how do i send to the correct variable...since the displaydata has more than one parameter
Last edited by gopi17; Aug 7th, 2009 at 5:53 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 147
Reputation: necrolin is on a distinguished road 
Solved Threads: 14
necrolin's Avatar
necrolin necrolin is offline Offline
Junior Poster

Re: Problems with function parameter...

 
0
  #2
Aug 7th, 2009
If you only pass one parameter to the function then what's the program supposed to do with the other 8?? Besides, regardless of the name of the variable that you're sending the data will go to the first parameter in the function. So basically you're sending row1col2 to row1col1... which is not what you want to do. Why can't you pass all 8 parameters at the same time? You can have the function enterdata1() just return the value to main and have main call the displaydata() function with all 8 parameters.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC