Okay so I have already taken off the macroguard and done everything all of the other forums have said to do but my if statement if (!indata) will print "cout" in the terminal regardless if the condition is met or not.
My program runs fine, it outputs to the file okay. It's the problem with the terminal I'm concerned with.
he is my code; I have highlighted the code in question:
PLEASE HELP ME, THANK YOU
My program runs fine, it outputs to the file okay. It's the problem with the terminal I'm concerned with.
he is my code; I have highlighted the code in question:
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;
const int BINARY = 2;
const int HEXADECIMAL = 16;
char DigitToChar (int digit);
// convert digit 0 to 16 to character
void ConvertNumber (int base, int number, ostream& outdata);
// convert decimal number to binary or hexadecimal
// writes result to outdata
int main()
{
ifstream indata;
ofstream outdata;
indata.open("data_input.txt");
outdata.open("data_output.txt");
int number;
[B]if (!indata)
{
outdata << "Missing Data Files!" << endl;
[COLOR="Red"]cout << "Missing Data Files!" << endl;[/COLOR]
system("PAUSE");
return EXIT_FAILURE;[/B]
}
indata >> number;
outdata << "Decimal Binary Hexadecimal" << endl;
while(indata)
{
outdata << setw(5) << number;
ConvertNumber(BINARY, number, outdata);
outdata << " ";
ConvertNumber(HEXADECIMAL, number, outdata);
outdata <<endl;
indata >> number;
}
indata.close();
outdata.close();
system("PAUSE");
return EXIT_SUCCESS;
}
char DigitToChar (int digit)
{
static char HexList[] = "0123456789ABCDEF";
return HexList[digit];
}
void ConvertNumber (int base, int number, ostream& outdata)
{
int digit;
char chdigit;
static int count;
count = 0;
if (number == 0)
outdata << setw(12-count) <<" ";
if (number > 0)
{
count++;
digit = number%base;
chdigit = DigitToChar(digit);
ConvertNumber(base, number/base, outdata);
outdata << chdigit;
}
}
PLEASE HELP ME, THANK YOU