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:

#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++ ;
}

Don't have time to check over the rest of the code, but I can tell you what is wrong here:

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.

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:

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
}

end quote.

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...

As for part 1, I believe the instructions are referring to c-strings...how much do you know about c-strings?

Ok, I've modified my code, and am getting an error that says:

[I]error C2563: mismatch in formal parameter list[/I]

This is at the same line with the comment [B]//error is here[/B]

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? =/

#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 ;
}

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.

As for part 1, I believe the instructions are referring to c-strings...how much do you know about c-strings?

i don't =/

As for part 1, I believe the instructions are referring to c-strings...how much do you know about c-strings?

I don't think so. Although, I don't know what the instructions mean, either.

Can you give us an example of the operation?

Just an update, thanks to everyone who helped. Here's the finalized code. This one is solved :D

/*****************************************************
* 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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.