I want to add big numbers but i get a wrong answer
//this is the size of the numbers
//"37107287533902102798797998220837590246510135740250"
// i have about 100 of them
int _tmain(int argc, _TCHAR* argv[])
{
ttmath::UInt<10> a[100];
ttmath::UInt<10> b;
string line[100];
int counter = 0;
ifstream myFile;
myFile.open ("num.txt");
if (!myFile.is_open())
{
cout<<"Error opening File"<<endl;
return 0;
}
for(int i = 0;( myFile.good() );i++)
{
getline (myFile,line[i]);
a[i] = line[i];
counter++;
}
counter = counter - 1;
// cout<<counter<<endl;
for (int i = 0;i<=counter-1;i++)
{
b = b + a[i];
}
cout<<"The total is: "<<b<<endl;
return 0;
Variable b is not initialized, give something like:
b = 0;
before the second for loop.