943,910 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 370
  • C++ RSS
Aug 7th, 2009
0

Problems with function parameter...

Expand Post »
I'm juz wondering how do I send a single value to a 8-parameter function...
C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
gopi17 is offline Offline
39 posts
since Sep 2008
Aug 7th, 2009
0

Re: Problems with function parameter...

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.
Reputation Points: 105
Solved Threads: 25
Posting Whiz in Training
necrolin is offline Offline
223 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: how does C++ know which constructor to call if you don't specify one?
Next Thread in C++ Forum Timeline: Good books for learning c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC