#include <iostream>
#include <fstream>

using namespace std;

void PrintError(fstream&, char, bool&);
int Conversion(fstream&, char&, bool&);

int main()
{
	fstream InFile;
	char Bit;
	int Decimal;
	bool BadBit = false;

	//Open file to read
	InFile.open("f:\\Binary.txt",ios::in);

	//Read the first bit of the number
	InFile.get(Bit);

	//continue reading all numbers till the end of file
	while (!InFile.eof())
	{
		//call Conversion to convert binary to decimal
		Decimal = Conversion(InFile, Bit, BadBit);

		//check if there is error
		if (BadBit)
		{
			//Print out error message 
			PrintError(InFile, Bit, BadBit);
		}
		else
			//output the equivalent value of decimal
			cout<<" = " <<Decimal<<endl;

		//read the next number
		InFile.get(Bit);		
	}

	InFile.close();

	return 0;
}

int Conversion(fstream& In, char& InBit, bool& Error)
/* Pre:  The stream is open for input.
         InBit is 1 or 0.
		 Error indicates the InBit is not One or Zero.
   Post: return the conversion of binary to decimal.
         Resets Error to true when encounter error.
*/
{
	
}


void PrintError(fstream& In, char BadOne, bool& Error)
/* Pre:  The stream is open for input.
         BadOne is bad digit.
		 Error indicates the BadOne is bad digit.
   Post: Prints error message.
         Resets Error to false means there is no error.
*/

{
	
}

Now that you've posted your code, is there a question you'd like to ask?

Please use full words and full sentences to explain what your problem is.

We don't do your work for you - read the notices at the top of the forum.

When you post code, it's more readable (thus more likely to get a good response) if you use the code tags to ensure its format comes through - indentation helps. Like this:

[code]

your code goes here

[/code]

That said, if you're reading the bits in main, why is the filestream passed to the converter? Pick one place to do the reading. If the size of the binary stream is not known, I'd go with the conversion function doing the reading, and adding the values up to make the decimal number as it reads in bits. Keep in mind that you'll be reading in the highest ordered bit first, and you don't know how high a power of 2 that is, do you? Or, are you sure to get formatted numbers (exactly 8 or 16 or 32 bits, for example)?

#include <iostream>
#include <fstream>

using namespace std;

void PrintError(fstream&, char, bool&);
int Conversion(fstream&, char&, bool&);

int main()
{
	fstream InFile;
	char Bit;
	int Decimal;
	bool BadBit = false;

	//Open file to read
	InFile.open("f:\\Binary.txt",ios::in);

	//Read the first bit of the number
	InFile.get(Bit);

	//continue reading all numbers till the end of file
	while (!InFile.eof())
	{
		//call Conversion to convert binary to decimal
		Decimal = Conversion(InFile, Bit, BadBit);

		//check if there is error
		if (BadBit)
		{
			//Print out error message 
			PrintError(InFile, Bit, BadBit);
		}
		else
			//output the equivalent value of decimal
			cout<<" = " <<Decimal<<endl;

		//read the next number
		InFile.get(Bit);		
	}

	InFile.close();

	return 0;
}

int Conversion(fstream& In, char& InBit, bool& Error)
/* Pre:  The stream is open for input.
         InBit is 1 or 0.
		 Error indicates the InBit is not One or Zero.
   Post: return the conversion of binary to decimal.
         Resets Error to true when encounter error.
*/
{
	
}


void PrintError(fstream& In, char BadOne, bool& Error)
/* Pre:  The stream is open for input.
         BadOne is bad digit.
		 Error indicates the BadOne is bad digit.
   Post: Prints error message.
         Resets Error to false means there is no error.
*/

{
	
}

i just wanted help wid the pre and post conditions...pls help wid d coding of it.....

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.