•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,375 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,051 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1368 | Replies: 8 | Solved
![]() |
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:
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:
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std ; void initialize ( int& , int& , char& ) ; void getHoursRate ( double& , double& ) ; double payCheck ( double& , double& ) ; void printCheck ( double , double, double ) ; int main() { int x ; int y ; int w ; char z ; double rate ; double hours ; double amount ; cout << initialize( x , y , z ) << endl ; //error is here cout << getHoursRate() << endl ; cout << payCheck( hours , rate ) << endl ; printCheck( hours, rate, amount ) << endl ; cout << funcOne( w, x, y ) ; //confusion starts here cout << } void initialize ( int& x, int& y, char& z ) { x = y = 0 ; z = ' ' ; } void getHoursRate ( double& hours , double& rate ) { cout << "Hours worked: " << endl ; cin >> hours ; cout << "Rate: " << endl ; cin >> rate ; } double payCheck ( double& hours, double& rate ) { double pay ; int ot ; if ( (hours - 40 <= 0 ) ) pay = rate * hours ; else { ot = hours - 40 ; pay = (40 * rate) + (ot * rate * 1.5) ; } return pay ; } void printCheck ( double hours , double rate , double pay ) { cout << setprecision(2) << fixed << showpoint << setfill('.') << left ; cout << "Hours" << setw(15) << "Rate" << setw(15) << "Amount Due" << endl << endl ; cout << hours << setw(15) << "$" << rate << setw(15) << "$" << pay << endl ; } void funcOne ( double in, int x, int y ) //number 2 in my post { cout << "Input a value: " << endl ; cin >> in ; x = x * x + ( y - in ) ; } char nextChar ( char ch ) //number 1 in my post { ch = ch++ ; }
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
-Edsger Dijkstra
Don't have time to check over the rest of the code, but I can tell you what is wrong here:
cplusplus Syntax (Toggle Plain Text)
cout << initialize( x , y , z ) << endl ; //error is here
initialize returns nothing, so cout has nothing to print. If you want to initalize the variables, try calling the function in a separate line instead of mixing it in with the cout call. tuxation.com - Linux articles, tutorials, and discussions
•
•
•
•
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.
code:
cplusplus Syntax (Toggle Plain Text)
void funcOne ( double in, int x, int y ) //number 2 in my post { cout << "Input a value: " << endl ; cin >> in ; x = x * x + ( y - in ) ; // <----Wrong }
With this function you are squaring x instead of doubling it (ie use 2*x instead of x*x). To test it, simply do some simple math in your head, using different values of x and y....then implement that in your code...if your code gives you different answers, then, unless you did the math wrong yourself, you know there is a problem with your code...
Ok, I've modified my code, and am getting an error that says:
error C2563: mismatch in formal parameter list
This is at the same line with the comment //error is here
I've called the void functions outside of a cout, and have put cout statements inside of the function to test them. What am I doing wrong? =/
error C2563: mismatch in formal parameter list
This is at the same line with the comment //error is here
I've called the void functions outside of a cout, and have put cout statements inside of the function to test them. What am I doing wrong? =/
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std ; void initialize ( int& , int& , char& ) ; void getHoursRate ( double& , double& ) ; double payCheck ( double& , double& ) ; void printCheck ( double , double, double ) ; void funcOne ( doulbe, int, int ) ; void nextChar ( char ) ; int main() { int x ; int y ; int w ; char z ; double rate ; double hours ; double amount ; initialize( x , y , z ) << endl ; //error is here getHoursRate() << endl ; cout << payCheck( hours , rate ) << endl ; printCheck( hours, rate, amount ) << endl ; funcOne( w, x, y ) ; //confusion starts here nextChar ( z ) ; } void initialize ( int& x, int& y, char& z ) { x = y = 0 ; z = ' ' ; cout << "Inside initialize-function: " << endl ; cout << "The values of 'x', 'y' and 'z', respectively are: " x << "\t" << y << "\t" << z << endl << endl ; } void getHoursRate ( double& hours , double& rate ) { cout << "Hours worked: " << endl ; cin >> hours ; cout << "Rate: " << endl ; cin >> rate ; cout << "Inside getHoursRate-function: " << endl ; cout << "The values of 'hours' and 'rate', respectively are: " << hours << "\t" << rate << endl << endl ; } double payCheck ( double& hours, double& rate ) { double pay ; int ot ; if ( (hours - 40 <= 0 ) ) pay = rate * hours ; else { ot = hours - 40 ; pay = (40 * rate) + (ot * rate * 1.5) ; } return pay ; } void printCheck ( double hours , double rate , double pay ) { cout << setprecision(2) << fixed << showpoint << setfill('.') << left ; cout << "Hours" << setw(15) << "Rate" << setw(15) << "Amount Due" << endl << endl ; cout << hours << setw(15) << "$" << rate << setw(15) << "$" << pay << endl ; } void funcOne ( double in, int x, int y ) //number 2 in my post { cout << "Input a value: " << endl ; cin >> in ; x = x * 2 + ( y - in ) ; cout << "Inside funcOne-function: " << endl ; cout << "The value of 'x' is: " << x << endl << endl ; } char nextChar ( char ch ) //number 1 in my post { cout << "Inside nextChar-function: " << endl ; cout << "Initial character stored in 'ch' is: " << ch << endl ; ch = ch++ ; cout << "The character stored in 'ch' after incriment is: " << ch << endl << endl ; }
Last edited by Duki : Apr 4th, 2007 at 3:06 pm.
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
-Edsger Dijkstra
initialize( x , y , z ) << endl ;You can't do this in C++ esp when initialize doesn't return anything and even if it did, you aren't specifying the stream to which the output should be redirected.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
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
-Edsger Dijkstra
Just an update, thanks to everyone who helped. Here's the finalized code. This one is solved 

c++ Syntax (Toggle Plain Text)
/***************************************************** * COSC 230 - Structured Programming * Chapter 7: Programming Exercise 1 * Apr. 4, 2007 * * Discription: * blah ******************************************************/ //header files #include <iostream> #include <iomanip> using namespace std ; //function prototypes void initialize ( int& , int& , char& ) ; void getHoursRate ( double& , double& ) ; double payCheck ( double& , double& ) ; void printCheck ( double , double, double ) ; void funcOne ( double, int, int ) ; void nextChar ( char ) ; int main() { int x ; int y ; int w ; char z ; double rate ; double hours ; double amount ; initialize( x , y , z ) ; //test initialize-func. getHoursRate(hours, rate) ; //test initialize-func. amount = payCheck( hours, rate ) ; //initialize amount to paycheck-func. cout << "*** Inside payCheck-function ***" << endl << payCheck( hours , rate ) << endl ; //test payCheck-func. printCheck( hours, rate, amount ) ; //test printCheck-func. funcOne( w, x, y ) ; //test funcOne-func. nextChar ( z ) ; //test nextChar-func. } void initialize ( int& x, int& y, char& z ) { x = y = 0 ; z = ' ' ; cout << "*** Inside initialize-function ***" << endl ; cout << "The values of 'x' and 'y', respectively are: " << x << " and " << y << endl ; cout << "The character stored in z is: " << z << "(space character)" << endl << endl ; }//end void initialize void getHoursRate ( double& hours , double& rate ) { cout << "Hours worked: " << flush ; cin >> hours ; cout << "Rate: " << flush ; cin >> rate ; cout << endl << "*** Inside getHoursRate-function ***" << endl << endl ; cout << "The values of 'hours' and 'rate', respectively are: " << hours << "\t" << rate << endl << endl ; }//end getHoursRate double payCheck ( double& hours, double& rate ) { double pay ; int ot ; if ( (hours - 40 <= 0 ) ) pay = rate * hours ; else { ot = hours - 40 ; pay = (40 * rate) + (ot * rate * 1.5) ; } return pay ; }//end double payCheck void printCheck ( double hours , double rate , double amount ) { cout << "*** Inside printCheck-function ***" << endl ; cout << setprecision(2) << fixed << showpoint << setfill('.') ; cout << "Hours" << setw(20) << right << "Rate" << setw(25) << right << "Amount Due" << endl ; cout << hours << setw(15) << "$" << rate << setw(15) << "$" << amount << endl << endl ; }//end void printCheck void funcOne ( double in, int x, int y ) { cout << "Input a value: " << flush ; cin >> in ; cout << endl ; x = x * 2 + ( y - in ) ; cout << "*** Inside funcOne-function ***" << endl ; cout << "The value of 'x' is: " << x << endl << endl ; }//end void funcOne void nextChar ( char ch ) { cout << "*** Inside nextChar-function ***" << endl ; cout << "Initial character stored in 'ch' is: " << ch << endl ; ch = ch++ ; cout << "The character stored in 'ch' after increment is: " << ch << endl << endl ; }//end nextChar
Last edited by Duki : Apr 5th, 2007 at 9:42 am.
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
-Edsger Dijkstra
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- User-defined functions (C++)
- using(STL)function object (bind2nd) with a user defined function object (C++)
Other Threads in the C++ Forum
- Previous Thread: priority queue using array!!!
- Next Thread: pragma



Linear Mode