I cant seem to get the input from the file into the array to work correctly. When I remove the file input portion and initialize the arrays in the code it works properly.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int n1[20];
int n2[20];
int ans[21];
int answer;
char tc;
I am not getting errors. I am just getting an unexpected output. I am just adding them together. When i program the arrays in it works correctly, so i figure the way i am geeting it from the file is incorrect.
Why are you reading it that way? That's about the hardest way you could possibly read
two integers from a file (hence my question).
Your code assumes that the file is formatted such that it is exactly 40 bytes in length,
no newlines, and the first integer is right justified in a field width of 20 characters
with leading zeros, and that the second integer is also right justified in a field width
of 20 characters with leading zeros.
Ie,
0000000000000000012800000000000000000256
would yield the right answer (128+256). Any other format to the file would cause your
program to generate erroneous output.
I am sorry I wasnt very clear. My problem states that 2 twenty digit numbers must be added together by use of arrays and I cant figure out how to read the numbers into an array correctly.