#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

	//Read the first bit of the number

	//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);
			//output the equivalent value of decimal
			cout<<" = " <<Decimal<<endl;

		//read the next number


	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.


hey guys can sum1 plsss do dis program for me.....trust me guys i have been doin it from 3 days but m not able to do it.......pls guys i have a submission tmr....thanks a lot

7 Years
Discussion Span
Last Post by WaltP

but its from decimal to binary....... n i really want sum1 to edit n work on d program i have given above....i really dont have time nor do i know how to do it....i tried as much as i could.....plsss sum1 edit my program n post it for me...

output should be as follows

1 = 1
10 = 2
11 = 3
12: Bad number!
10000 = 16
10101 = 21
13: Bad number!
end: Bad number!


Plz rd da rulz uv da forum, an da stickies at da top. Stop using baby talk, we are adults here. And we are not a free homework service.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.