C/C++ >> help me please
Posted by holguie81 on 00:02:00 07-13-2003
I am currently unrolled in a introductory C++ class and I just don't get this assignment can some one please help me.

Write a program that reads characters representing binary (base-2) from a data file and translates them to decimal base (base-10) numbers the binary and decimal numbers should be out put in two columns with appropriate headings here is a sample of the out put:

Binary Number Decimal Equivalent
1 1
10 2
11 3
10000 16
10101 21

There is only one binary number per input line, but an arbitrary number of blanks can precede the number. The program must read the binary numbers one character at a time. As each character is read, the program multiplies the total decimal value by 2 and adds either 1 0r 0, depending on the input character. The program should check for bad data; if it encounters any thing except a 0 or a 1, it should out put the message "Bad digit on input."

I am to the point where my program can get the character one at time (left to right). I understand how to do the math but I just can't figure out how to assign the pow() since the program is reading the characters left to right.

This is what I have so far I hope I am on the right track.

#include
#include // For file I/O
#include // For sting data type

using namespace std;

int main()
{

ifstream inFile; // Data file


// Promts the user for a file name.

string fileName; // File name
string binary;
char currentChar;
int newChar0;
int newChar1;
int loopCount;

cout --> fileName;
cout 49)
{
cout