I need to create a program that is a table to convert between centigrade and fahrenheit temperatures. My solution must must utilize functions to perform the conversions. Requirements:
1. One of the functions must use pass-by-value, returning the converted
measure
2. One of the functions must use pass-by-reference to store its result (the
function does not have a return value).
Program must create two tables - one showing the centigrade equivalent to
fahrenhrit measures from 0 degrees centigrade to 100 degrees centigrade (by 5
degree increments: 0, 5, 10, . . . , 100) and the other showing fahrenheit
equivalent to centigrade measures 0 through 100 (by 5 degree increments: 0, 5,
10, ... , 100). Original measures are all integer values. Calculated measures are to
be displayed accurate to two decimal places. The output for both tables must fit on
one default screen (78 columns by 22 rows), so your tables will need to be
organized into multiple columns. Everything must be lined up nicely and the tables
neatly and informatively labeled.

Well I got the program to line up correctly, but I want to see if the pass-by and pass values were correct. Can someone look at this and steer me correctly.

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

int main()
{
	float i=0;
    float c= 0;
	float &f= c;
	

    cout << setw(25) << "Centigrade to Fahrenheit" 
		<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;
        
	cout << setw(6) << "Cent" << setw(18) << "Fahr" 
		<< setw(17) << "Fahr" << setw(19) << "Cent\n";; 
			

	for ( float i = 0; i <= 100; i+=5 )
   {
      float f = ((i * 9/5) + 32);
	  float c = ((i - 32)* 5/9);
	  	  
      cout << setw(6) << setprecision(0) << i << setw( 18 ) 
		  << setprecision(2)<< fixed << f << setw(17) 
		  << setprecision(0) << i  << setw(18) 
		  << setprecision(2) << c << endl;
   }
   	
   return 0;
}

I also have a second version which I tried to use funsction but I get error after error. Can I get help with that one too?

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

int centToFahr(float);
void centToFahr(float&);
int fahrToCent(float);
void fahrToCent(float&);

int main()
{
	float i=0;
	float c=0;
	float f=0;
    

    cout << setw(25) << "Centigrade to Fahrenheit" 
		<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;
        
	cout << setw(6) << "Cent" << setw(18) << "Fahr" 
		<< setw(17) << "Fahr" << setw(19) << "Cent\n";; 
			

	for ( float i = 0; i <= 100; i+=5 )
   {
      /*float f = ((i * 9/5) + 32);
	  float c = ((i - 32)* 5/9);*/
	  	  
      cout << setw(6) << setprecision(0) << i << setw( 18 ) 
		  << setprecision(2)<< fixed << centToFahr(f) << setw(17) 
		  << setprecision(0) << i  << setw(18) 
		  << setprecision(2) << fahrToCent(c) << endl;
   }
   	
   return 0;
}
float centToFahr(float i, float f)
{
	return f = ((i * 9/5) + 32);
}
float fahrToCent(float i, float c)
{
	return c = ((i - 32)* 5/9);
}

Thank you,
M

It sounds like you only need one of the two sets of functions listed below:

float centToFahr(int);
void fahrToCent(int, float &);

void centToFahr(int, float &);
float fahrToCent(int);

The int value is the number to be converted from one scale to the other. The float is the number after the conversion. The float is either passed back as a return type or it's passed by reference. I'll arbitrarily choose the second set of functions.

Within the for loop I'd call both functions:

for (int i = 0; i < 100; i += 5 )
{
   centToFahr(i, f);
   c = fahrToCent(i);

   //output f and c however you want
}

and I'd define the functions like this:

void centToFahr(int i, float & f)
{
   f = ((i * 9/5) + 32);
}

float fahrToCent(int i)
{
    float temp;
    temp = ((i - 32) * 5/9);
    return temp;
}

The biggest problem I see with your code is that you don't consistently use the same number of parameters in the function prototypes, function calls and function definitions.

Your first code section won't pass the requirements specs - it doesn't use any functions.
The second section won't compile because you have mismatches between your function declarations and your function definitions.

I have worked on it, but I seem to have a few compile errors. Where am I going wrong?

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


float centToFahr(float, float);
void fahrToCent(float, float &);


int main()
{
	 

    cout << setw(25) << "Centigrade to Fahrenheit" 
		<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;
        
	cout << setw(6) << "Cent" << setw(18) << "Fahr" 
		<< setw(17) << "Fahr" << setw(19) << "Cent\n";; 
			

	for (float i = 0; i < 100; i += 5 )
	{
		float f = 0;
		

		centToFahr(i,f);
		float c = fahrToCent(i);

		cout << setw(6) << setprecision(0) << i << setw( 18 ) 
			<< setprecision(2)<< fixed << c << setw(17) 
			<< setprecision(0) << i  << setw(18) 
			<< setprecision(2) << fahrToCent << endl;
	}
   	
   return 0;
}
void centToFahr(float i, float & f)
{
   f = ((i * 9/5) + 32);
}

float fahrToCent(float i)
{
    float temp;
    temp = ((i - 32) * 5/9);
    return temp;
}

I have been working on this and I think I have the formulas right, but the centigrade and the fahrheit will not calculate. any suggestions...??

#include <iostream>
using std::cout;
using std::endl;

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

float cTF(float);
void fTC(float &);

int main()
{
	float c = 0;
    float f = c;
		

    cout << setw(25) << "Centigrade to Fahrenheit" 
		<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;
        
	cout << setw(6) << "Cent" << setw(18) << "Fahr" 
		<< setw(17) << "Fahr" << setw(19) << "Cent\n";; 
			

	for ( float i = 0; i <= 100; i+=5 )
   {
      	  	  
      cout << setw(6) << setprecision(0) << i << setw( 18 ) 
		  << setprecision(2)<< fixed << f << setw(17) 
		  << setprecision(0) << i  << setw(18) 
		  << setprecision(2) << c << endl;
   }
   	
   return 0;
}
float cTF(float f)
{
	f= ((f * 9/5) + 32);

	return f; 
}
void ftC(float c)
{
	c =((c - 32)* 5/9);
}

You never actually call your functions. That's why they're not doing anything. Put your function calls in the loop. You also need to check your functions. You have the prototype for fTC as fTC and the definition as ftC . Your compiler probably doesn't care right now since it doesn't try to use either of them, but when you try to call your function you will get compile-time errors.

First off, I would put

using namespace std;

instead of enumerating the standard objects.

The others are correct in what they have observed as problems. You don't use your functions.

Have you been taught how to use arrays? Using them would simplify this greatly.

I re-did the entire program. I got every thing completed but the Pass Value & Pass-by-Reference.

How can I incorporate these two?

#include <iostream>
using std::cout;
using std::endl;

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

float cent(float); // function prototype
float fahr(float); // function prototype

int _tmain(int argc, _TCHAR* argv[])
{
	// display table 
	cout << "Centigrade to Fahrenheit" << setw(30) << "Fahrenheit to Centigrade" << endl;

	// create 4 columns

	for ( int t = 0; t < 1; t++ )
		cout << setw(8) << "Cent" << setw( 14 ) << "Fahr" << setw(16) << "Fahr" << setw(14) << "Cent" ;

	cout << endl;

	for ( float a = 0; a <=100; a+=5 ) 
		{
			for ( float b = 0; b <= 5; b += 25 )

				cout << setw( 8) << setprecision(0)<< a + b << setw( 14 ) << setprecision(2) << fixed << fahr( a + b ) << ' ' 
				<< setw( 15) << setprecision(0) << a + b << setw( 14 ) << setprecision(2) << fixed << cent( a + b ) << ' ';

			cout << endl;

			} 

	return 0; // 

}  // end main

// function cent
float cent( float f )
{
	return ( 5.0 / 9.0 * ( f - 32 ) );

	} // end function cent

// funtion fahr 
float fahr( float c )
{
	return ( 9.0 / 5.0 * c + 32 );

	} // end function fahr

I realize that using namespace would be a great deal effective, but my professor require us to to it that way. Believe me I would rather. As for Arrays, that is next chapter.
I appreciate any and all ways of doing things better.
M

First:
Go back to the what you had (post #5). You're program was originally (essentially) correct. The only thing missing was the calls to the functions that do the calculations. Here's an example (I lifted directly from your original code)

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

		c = i;
		fTC(c); //<-This is your function call.

Second:
Within the same loop, you can call your cTF function inline with your formatted output. You can get away with this because cTF returns a value.

cout << setw(6) << setprecision(0) << i << setw( 18 ) 
		  << setprecision(2)<< fixed << cTF(i) /*<-Here's another function call, with out no calculations get done*/

Third:
Don't forget to use meaningful variable names, 1 letter is great for a simple counter but a single letter tends to get lost in the code - a bad situation when you've got a lot of lines to read.

In the first part, you'll notice that you assign the current value of i to c - this will allow you to pass c to your function so that it is calculated for the given i. Since the fTC modifies whatever variable it's given - you can't pass it i because it would change the value of main::i and cause all sorts of headaches.

I am having a difficult time getting it to compile. Somewhere there is a major error and I can not see it. I tried to follow along to your directions, but I can not get it to work. I went back to my old program too.

#include <iostream>
using std::cout;
using std::endl;

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

float ctF(float);
void ftC(float &);

int main()
{
	cout << setw(25) << "Centigrade to Fahrenheit" 
		<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;
        
	cout << setw(6) << "Cent" << setw(18) << "Fahr" 
		<< setw(17) << "Fahr" << setw(19) << "Cent\n";; 
			

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

	   float c = i;
	   ftC(c);
	  
      	  	  
      cout << setw(6) << setprecision(0) << i << setw( 18 ) 
		  << setprecision(2) << fixed << ftC(i) << setw(17) 
		  << setprecision(0) << i  << setw(18) 
		  << setprecision(2) << ctF(i) << endl;
   }
   	
   return 0;
}
float ctF(float f)
{
	f= ((f * 9/5) + 32);

	return f; 
}
void ftC(float c)
{
	c =((c - 32)* 5/9);
}

What is wrong??
M

<< setprecision(2) << ctF(i) << endl Here's your problem. You can't call ctF(i) here because the function has no return value (which means, as far as cout is concerned, there's nothing there but some stuff it has no clue how to handle). The value you want there is just c . That's why, in the beginning of the loop, you have to assign c the value of i - because the function is going to actually change c without returning anything (That's the beauty of passing arguments by reference). The output code should look like this.

cout << setw(6) << setprecision(0) << i << setw( 18 ) 
		  << setprecision(2) << fixed << ftC(i) << setw(17) 
		  << setprecision(0) << i  << setw(18) 
		  << setprecision(2) << c /*<-Here's the change*/ << endl;

I can not get it to compile. I get 15 errors

#include <iostream>
using std::cout;
using std::endl;

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

float ctF(float);
void ftC(float &);

int _tmain(int argc, _TCHAR* argv[])
{
	cout << setw(25) << "Centigrade to Fahrenheit" 
		<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;
        
	cout << setw(6) << "Cent" << setw(18) << "Fahr" 
		<< setw(17) << "Fahr" << setw(19) << "Cent\n";; 
			

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

	   float c = i;
	   ftC(c);

	   cout << setw(6) <<setprecision(0) << i << setw(18) << setprecision(2) <<  ftC(i) << setw(17)
		   setprecision(0) << i << setw(18) <<setprecision(2) << c << endl;

   }
   	
   return 0;
}
float ctF(float f)
{
	f= (f * 9/5 + 32);

	return f; 
}
void ftC(float c)
{
	c =((c - 32)* 5/9);
}
.cpp(33) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)

c:\program files\microsoft visual studio 8\vc\include\ostream(650): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(697): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(735): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(782): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(906): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(913): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(920): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(927): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(168): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(174): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(181): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(188): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(208): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(241): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(261): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(286): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned int)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(306): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(326): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned long)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(347): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(367): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(388): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(408): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(428): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(448): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(468): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        while trying to match the argument list '(std::basic_ostream<_Elem,_Traits>, void)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2146: syntax error : missing ';' before identifier 'setprecision'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\iomanip(80) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::_Fillobj<_Elem> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\iomanip(47) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(927) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(920) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(913) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(906) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(868) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(822) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(782) : see declaration of 'std::operator <<'
1>c:\users\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(735) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\ostream(697) : see declaration of 'std::operator <<'
1>c:\users\moporho\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::_Smanip<_Arg>'
1>        with
1>        [
1>            _Arg=std::ios_base::fmtflags
1>        ]
   c:\program files\microsoft visual studio 8\vc\include\ostream(650) : see declaration of 'std::operator <<'
c:\users\documents\visual studio 2005\projects\help\help\help.cpp(34) : error C2676: binary '<<' : 'std::_Smanip<_Arg>' does not define this operator or a conversion to a type acceptable to the predefined operator

15 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Sorry for that It was way longer than I expected.
M

Can anyone tell me why this will not compile?

#include <iostream>
using std::cout;
using std::endl;

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

float ctF(float c);
void ftC(float &);

int main()
{
cout << setw(25) << "Centigrade to Fahrenheit" 
<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;

cout << setw(6) << "Cent" << setw(18) << "Fahr" 
<< setw(17) << "Fahr" << setw(19) << "Cent\n";; 


for ( float i = 0; i <= 100; i+=5 )
{
float c=i;
ftC(c);

cout << setw(6)  setprecision(0) << fixed << i << setw(18)
<< setprecision(2) << fixed << ftC(i) << setw(17)<< setprecision(0)
<< fixed << i  << setw(18)<< setprecision(2) << fixed << c << endl;
}

return 0;
}
float ctF(float f)
{
	f = ((f * 9/5) + 32);

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

thank you,
m

What exactly are you trying to display here? (see red):

cout << setw(6)  setprecision(0) << fixed << i << setw(18)
<< setprecision(2) << fixed << ftC(i) << setw(17)<< setprecision(0)
<< fixed << i  << setw(18)<< setprecision(2) << fixed << c << endl;

ftC is a void function. If you want to display i after it has been changed by this function, you need to call the function, then display i, not ftC(i). The compiler has no idea that you are trying to display i here (if that's what you are trying to do).

void ftC(float &);

That function call is supposed to be ctF(i). Your output sections should be:

cout << setw(6) << setprecision(0) << i << setw( 18 ) 
		  << setprecision(2) << fixed << ctF(i)/*<-This has to change too*/ << setw(17) 
		  << setprecision(0) << i  << setw(18) 
		  << setprecision(2) << c << endl;
commented: Brilliant - Awesome Teacher +1

No, actually what he has is better form.
"Using namespace" is quick time saving tool
that brings the entire std library into scope.
It's OK for assignments, unless the instructor says otherwise.

In "real world" programming this is considered namespace pollution!
Just declare what you need...

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.