RSS Forums RSS
Please support our C++ advertiser: Programming Forums

User-Defined Function - part 2

Join Date: Jun 2006
Location: USA
Posts: 1,082
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Rep Power: 7
Solved Threads: 4
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

Help User-Defined Function - part 2

  #1  
Apr 4th, 2007
Hey everyone, this is a big one.

The question has asked that I define functions and then write the function main to test the functions I wrote. I keep getting the following error at my first cout in main:

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)

I'm not sure what this is saying.
In addition, I need help with defining two of my functions and writing code to test them. They are as follows:

1. Write the definition of the function nextChar that sets the value of z to the next character stored in z.

2. Write the definition of the function funcOne that prompts the user to input a number. The function then changes the value of x to 2 times the old value of x plus the value of y minus the value entered by the user.

Now, with #2 I'm pretty sure I have the function defined right, though I don't know how to test it. #1 though, I have no clue how to define that function, though I did attempt it =/.

Could someone look through my code, and let me know if they notice any huge mistakes? This is our second chapter on user-defined functions, so I'm still learning about call by reference and whatnot. I have commented my code minimaly to assist you in finding the parts I'm having a tough time with.

Thanks guys! :mrgreen:

code:

  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std ;
  4.  
  5. void initialize ( int& , int& , char& ) ;
  6. void getHoursRate ( double& , double& ) ;
  7. double payCheck ( double& , double& ) ;
  8. void printCheck ( double , double, double ) ;
  9. int main()
  10. {
  11. int x ;
  12. int y ;
  13. int w ;
  14.  
  15. char z ;
  16.  
  17. double rate ;
  18. double hours ;
  19. double amount ;
  20.  
  21. cout << initialize( x , y , z ) << endl ; //error is here
  22. cout << getHoursRate() << endl ;
  23. cout << payCheck( hours , rate ) << endl ;
  24. printCheck( hours, rate, amount ) << endl ;
  25. cout << funcOne( w, x, y ) ; //confusion starts here
  26. cout <<
  27. }
  28.  
  29. void initialize ( int& x, int& y, char& z )
  30. {
  31. x = y = 0 ;
  32. z = ' ' ;
  33. }
  34.  
  35. void getHoursRate ( double& hours , double& rate )
  36. {
  37. cout << "Hours worked: " << endl ;
  38. cin >> hours ;
  39. cout << "Rate: " << endl ;
  40. cin >> rate ;
  41. }
  42.  
  43. double payCheck ( double& hours, double& rate )
  44. {
  45. double pay ;
  46.  
  47. int ot ;
  48.  
  49. if ( (hours - 40 <= 0 ) )
  50. pay = rate * hours ;
  51. else
  52. {
  53. ot = hours - 40 ;
  54. pay = (40 * rate) + (ot * rate * 1.5) ;
  55. }
  56. return pay ;
  57. }
  58.  
  59. void printCheck ( double hours , double rate , double pay )
  60. {
  61. cout << setprecision(2) << fixed << showpoint << setfill('.') << left ;
  62. cout << "Hours" << setw(15) << "Rate" << setw(15) << "Amount Due" << endl << endl ;
  63. cout << hours << setw(15) << "$" << rate << setw(15) << "$" << pay << endl ;
  64. }
  65.  
  66. void funcOne ( double in, int x, int y ) //number 2 in my post
  67. {
  68. cout << "Input a value: " << endl ;
  69. cin >> in ;
  70.  
  71. x = x * x + ( y - in ) ;
  72. }
  73.  
  74. char nextChar ( char ch ) //number 1 in my post
  75. {
  76. ch = ch++ ;
  77. }
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:40 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC