I am very new to C++ and I have a project due tomorrow in my C++ class and I'm rather stuck. I have to convert a binary value from an input file (the name of which is given by the user) and then convert the binary to decimal value and print that in an output file.
Right now it is compiling just fine with no error messages, but when I run the program, it doesn't end or print to the output file.
I know that this is last minute and late, but any ideas or help would be great and very much appreciated!!
Here is my code at the moment:
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//function prototypes
char convertBinary (char);
int main()
{
ifstream fcin;
ofstream fcout;
char inputFileName[50]; //store file name entered by user
char ch; //single character to store user input
char outputFileName[50]; //store output file name
char output;
cout <<"Enter the input file name" << endl;
cin >> inputFileName; //read in user file name
cout <<"Enter file name where output is to be stored: " << endl;
cin >> outputFileName;
fcin.open("inputFileName"); // open the input file
fcin.get(ch); //read a character ch from the input file
while(ch)
{
cin.ignore(10, ' ');
cin.get(bin1);
cin.get(bin2);
while(bin2 != '\n'|| ' ')
{
if (bin1 == '0')
sum = sum + 0;
else if (bin1 == '1')
sum = sum + 1;
else cout << "Bad digit on input.";
sum = sum * 2;
cout << bin1;
bin1 = bin2;
cin.get(bin2);
}
if (bin1 == '0'){
sum = sum + 0;
}
else if (bin1 == '1')
sum = sum + 1;