I'm getting a few error codes on this part of my lab. I showed it to another colleague and he said that it should work as written. Maybe one of you can see the error that I'm missing. I'd love to be done with it and get it turned in.

//*****************************************************************************
// 				BEGINNING OF PROGRAMMING CODE
//*****************************************************************************
/* there's a bunch of other functions here, but they aren't part of the problem so I'm going to save space and not include them here */

void centerLine(const string &text, unsigned int lineLength)
// this prints out a pretty center bar line
{
	cout << setw.((text.length() + lineLength) /2) << text << endl;
}

void printDoubleHorizontalLine(unsigned int lineLength)
//  they're actually '=' characters, but they look like double lines
{
	char currentFill = cout.fill('=');
	
	cout << setw(lineLength) << '=' << endl;
	cout.fill(currentFill);
}

/*
ERRORS

1>------ Build started: Project: IOpractice, Configuration: Debug Win32 ------
1>Build started 11/13/2010 12:23:51 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\IOpractice.unsuccessfulbuild".
1>ClCompile:
1>  SphereFunctions.cpp
1>c:\users\mommabear\documents\visual studio 2010\projects\215\new folder\iopractice\iopractice\spherefunctions.cpp(103): error C2059: syntax error : '('
1>c:\users\mommabear\documents\visual studio 2010\projects\215\new folder\iopractice\iopractice\spherefunctions.cpp(109): error C2228: left of '.cout' must have class/struct/union
1>          unable to recover from previous error(s); stopping compilation
1>  Lab2Main.cpp
1>  Generating Code...
1>
1>Build FAILED.
1>
*/

There seems to be an extraneous period there .. cout << setw[B].[/B]((text.length() + lineLength) /2) << text << endl;

There seems to be an extraneous period there .. cout << setw[B].[/B]((text.length() + lineLength) /2) << text << endl;

Whoo, boy - the compiler screamed at me when I did that. I can post more of the file if you need to see it. The lab is entirely done except for those errors originally in red. Here's the errors from taking away the period.

1>c:\users\mommabear\documents\visual studio 2010\projects\215\new folder\iopractice\iopractice\spherefunctions.cpp(103): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(726): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(764): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(811): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(937): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(944): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(951): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(958): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(968): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>,std::string>(std::basic_ostream<_Elem,_Traits> &&,_Ty)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ty=std::string
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(1085): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(186): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(192): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(199): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(206): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(226): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(260): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(280): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(305): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(325): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(345): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(366): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(386): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(407): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(427): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(447): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(467): 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 (x86)\microsoft visual studio 10.0\vc\include\ostream(487): 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>, const std::string)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>
1>Build FAILED.

>> the compiler screamed at me when I did that.

Sometimes that happens -- anyway, having that period there is certainly wrong. Are you sure there are ..

#include <string>
#include <iomanip>
#include <iostream>

Error is gone, but check whether it is working the way you want

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void centerLine(const string &text, unsigned int lineLength);
void printDoubleHorizontalLine(unsigned int lineLength);

int main()
{
   	
	centerLine("hi",10);
	printDoubleHorizontalLine(10);

  return 0;
}

void centerLine(const string &text, unsigned int lineLength)
// this prints out a pretty center bar line
{
	cout << setw((int)(text.length() + lineLength)/2) << text << endl;
}

void printDoubleHorizontalLine(unsigned int lineLength)
//  they're actually '=' characters, but they look like double lines
{    char currentFill;
	 currentFill = cout.fill('=');

     cout << std::setw(lineLength) << '=' << endl;
	 cout.fill(currentFill);
}

Ok, so I fixed the original problem, and it Does compile and run. Thanks for the insight.

Code Corrected:

void centerLine(const string &text, unsigned int lineLength)
// this prints out a pretty center bar line
{
	cout << setw((text.length() + lineLength) /2) << text << endl;
}

Since you did such a great job with that, could you explain to me why this function isn't displaying any results, please?

// in header file
extern void printBinary( int inNum, int numDigits = 8 );

//in free function file
void printBinary(int inNum, int numDigits)		// this puts the value in base 2
{
	for(int shiftAmt = numDigits = -1; shiftAmt >=0; shiftAmt--)
	{
		cout << ((inNum >> shiftAmt) & 01 );
	}
	char currentFill = cout.fill('.');
	
	cout << setw(20 - numDigits) << '.';
	cout.fill(currentFill);
}

>> why this function isn't displaying any results, please?

You initialize shiftAmt to -1 and the loop only executes when shiftAmt >=0 .

Yes there is problem with your initialization and condition. Are you trying to make a binary divider or multiplier using shift technique? If yes I might be able to help you if you let me know how much you have to shift.

Yes there is problem with your initialization and condition. Are you trying to make a binary divider or multiplier using shift technique? If yes I might be able to help you if you let me know how much you have to shift.

The binary is a conversion from a decimal num. I'm given an object of a class (in this case, a sphere) with a single data member (radius) and produce member functions that compute and return values for the Circumference and Volume of the object.

The output should show the original value as a decimal, the binary conversion, and then the hex and scientific notation values. What I have is:

the function prototypes in the header

extern void printDecimal( long inNum );
extern void printHex( long inNum );
extern void printBinary( int inNum, int numDigits = 8 );
extern void printScientific( float inNum );
extern void centerLine( const std::string &text, unsigned int lineLength );
extern void printDoubleHorizontalLine(unsigned int lineLength);

the function implementations

//*****************************************************************************
// 				INCLUDE FILES
#include <iostream>				// for cin,cout
#include <iomanip>				// for formatting cout
#include <string>
#include "SphereFunctionHeader.h"	// for linking to main cpp file

using namespace std;
//***********************************************************************************

void printDecimal (long inNum)		//this is what fills in the '.'
{
	char currentFill = cout.fill('.');		// getter to current Fill
	long currentFlags = cout.flags();		// getter to current Flags

	cout << left << setw(20) << inNum;
	cout.fill(currentFill);					
	cout.flags(currentFlags);
}


void printHex(long inNum)				// this puts the value in base 16 format
{
	char currentFill = cout.fill('.');
	long currentFlags = cout.flags();

	cout.setf(ios::hex, ios::basefield);
	cout.setf(ios::showbase);
	cout << left << setw(20) << inNum;
	cout.fill(currentFill);				// reset Fill value
	cout.flags(currentFlags);			// reset Flags value
}

void printBinary(int inNum, int numDigits)		// this puts the value in base 2
{
	for(int shiftAmt = numDigits = 0; shiftAmt >=-1; shiftAmt--)
	{
		cout << ((inNum >> shiftAmt) & 01 );
	}
	char currentFill = cout.fill('.');
	
	cout << setw(20 - numDigits) << '.';
	cout.fill(currentFill);
}

void printScientific(float inNum)		// this puts the value in Scientific Notation
{
	long currentFlags = cout.flags();
	int oldPrecision = cout.precision();
	
	cout.precision(2);
	cout.setf(ios::scientific, ios::floatfield);
	cout << inNum;
	cout.flags(currentFlags);
	cout.precision(oldPrecision);
}

void centerLine(const string &text, unsigned int lineLength)
// this prints out a pretty center bar line
{
	cout << setw((text.length() + lineLength) /2) << text << endl;
}

void printDoubleHorizontalLine(unsigned int lineLength)
//  they're actually '=' characters, but they look like double lines
{
	char currentFill = cout.fill('=');
	
	cout << setw(lineLength) << '=' << endl;
	cout.fill(currentFill);
}

And this is my Output:

RADIUS++++++++++++++RADIUS++++++++++++++CIRCUMFERENCE+++++++VOLUME++++++++++++++

DECIMAL             BINARY              HEXADECIMAL         SCIENTIFIC

================================================================================

20..................00....................0x7d................3.35e+004
21..................10....................0x83................3.88e+004
22..................00....................0x8a................4.46e+004
23..................10....................0x90................5.10e+004
24..................00....................0x96................5.79e+004
25..................10....................0x9d................6.54e+004
26..................00....................0xa3................7.36e+004
27..................10....................0xa9................8.24e+004
28..................00....................0xaf................9.20e+004
29..................10....................0xb6................1.02e+005
30..................00....................0xbc................1.13e+005

================================================================================

I erased ONE thing and fixed it. Man, I love this stuff.

Changed

for(int shiftAmt = numDigits = -1; shiftAmt >=0; shiftAmt--)

to

for(int shiftAmt = numDigits -1; shiftAmt >=0; shiftAmt--)
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.