Hey guys
Need help with the following program. I keep getting compilation error

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

Apparently I am not able to pass by reference however it works well when I pass by value.
The assignment requires a pass by reference function or I would just do pass by value.
My dilemma is how do I call the pass by reference function properly.
I am desperate. Please help anyone!

#include "stdafx.h"
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;


#include <iomanip>
using std::setw;
using std::setprecision;
using std::fixed;


float cent(float); // function prototype (pass by value)
void fahren(float &); // function prototype (pass by reference)


// function main begins program execution
int main()
{
float centi = 0;
float fah = centi;


// displays table information
cout << setw(25) << "Centigrade to Fahrenheit" << setw(30)
<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;


// two tables are created
cout << setw(8) << "Centigrade" << setw (16) << "Fahrenheit" // table for centigrade to fahrenheit
<< setw(18) << "Fahrenheit" << setw(16) << "Centigrade"; //table for fahrenheit to centigrade
cout << endl;


for (float i = 0; i <= 100; i+= 5)
{
centi = i;
for (float j = 0; j <= 5; j+= 25)


cout << setw(6) << setprecision(0) << i + j << setw(18)
<< setprecision(2) << fixed << fahren(centi) << ' ' << setw(15)
<< setprecision(2) << i + j << setw(18) << setprecision(2) << fixed << cent(i + j) << ' ' << endl;
}


return 0;
}


float cent(float f)
{
f = ((f * 9/5) + 32);
return f;
}void fahren( float &c)
{
c = ((c - 32) * 5/9);


}

The function's type is void and you are trying to display it :p

Call the function and then send the variable to cout.

fahren(centi);
cout << setw(6) << setprecision(0) << i + j << setw(18)
<< setprecision(2) << fixed << centi<< ' ' << setw(15)
<< setprecision(2) << i + j << setw(18) << setprecision(2) << fixed << cent(i + j) << ' ' << endl;
}

Thank you minas1, it worked. However my calculations from centigrade to fahrenheit does not seem accurate. I will continue work on it.

Does the calculations appear accurate? If not, any suggestions?

The function's type is void and you are trying to display it :p

Call the function and then send the variable to cout.

fahren(centi);
cout << setw(6) << setprecision(0) << i + j << setw(18)
<< setprecision(2) << fixed << centi<< ' ' << setw(15)
<< setprecision(2) << i + j << setw(18) << setprecision(2) << fixed << cent(i + j) << ' ' << endl;
}

Trying doing 9.0/5.0 rather than just 9/5

Chris

Chris,
Appreciate your suggestion. I tried that but got this error message:
conversion from 'double' to 'float', possible loss of data
I even converted all floats to doubles and got the same calculations as when they were floats.
Maybe the error is in the for loop!

Trying doing 9.0/5.0 rather than just 9/5

Chris

You are right Chris, the calculations do work. Apparently I overlooked the - (negative) I got for my previous calculations(when it was 9/5 and designated float).
The - (negative) is now gone after changing all floats to doubles and 9/5 to 9.0/5.0.

Thanks a lot.

Good sorry i should of paid attention to the fact you were using floats, i would then of suggested 9.0f/5.0f :P

Glad its sorts, if there are no more problems then mark thread as solved

Chris

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.