d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Reading From A File > Pretty Basic Except The Arithmetic
Add Reply New Topic New Poll
Member
Posts: 23,517
Joined: Aug 3 2011
Gold: 3,575.00
Nov 24 2017 12:48pm
File contains:

AAA+BCDEF (converting to hexadecimal first)
But the issue I have is with the actual addition function. I get 0 output from the console, not even 0. I'm not sure how to read the file "AAA+BCDEF". Thought the ifstream would pass it but now I'm just confused. Help?
Code


void addHex(ifstream inFile)
{
char ch;
long int num1 = 0;
long int num2 = 0;

inFile << ToHexdecimal(num1) << ToHexdecimal(num2);
ToHexdecimal(num1) + ToHexdecimal(num2);

}


string ToHexdecimal(long int decimalNum)
{
long int result;
int tempVal;

stack <char> hexDecimal;
string hexString;
stringstream concat;

result = decimalNum;

while (result != 0)
{
tempVal = result % 16;

if (tempVal < 10)
{
tempVal += 48;
}
else
{
tempVal += 55;
}

hexDecimal.push(tempVal);
result /= 16;
}
while (!hexDecimal.empty())
{
concat << hexDecimal.top();
hexString = concat.str();
hexDecimal.pop();
}
return hexString;
}
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll