Hi,

i'm trying to calculate 100! for a project Euler problem. However, i ran into an issue while testing. The program does a correct calculation of 14! when i check the answer against google calculator. However, 15! and above doesn't give a correct answer. I've been at it for a while, so i appreciate any input:

Code:int main() { vector<int> digits(1,1); int power; cout << " enter factorial base:"; cin >> power; for (int i=1 ; i <= power ; ++i) { vector<int> multiplier; auto tmpi = i; while( tmpi != 0 ) { multiplier.push_back(tmpi % 10); tmpi /= 10; } auto mulit = multiplier.begin(); int pos = 0; vector<int> tmpvector(digits); while (mulit != multiplier.end()) { deque<int> tmpdeque; for (int j = 0 ; j < pos ; ++j) tmpdeque.push_back(0); /* cout << "tmpdeque init " << pos << "multi=" << (*mulit) << " |"; copy(tmpdeque.begin(),tmpdeque.end(),ostream_iterator<int>(cout,"")); cout << endl; */ int addforward = 0; for (auto it = digits.begin() ; it != digits.end() ; ++it) { int tmp = (*it) * (*mulit) + addforward; tmpdeque.push_back(tmp % 10); addforward = tmp / 10; /* cout << "in tmpdeque tmp="<< tmp << " it-> " << (*it) << " multi->"<< (*mulit); cout << "\n"; copy(tmpdeque.rbegin(),tmpdeque.rend(),ostream_iterator<int>(cout,"")); cout << "\n"; copy(digits.rbegin(),digits.rend(),ostream_iterator<int>(cout,"")); cout << endl; */ } if (addforward != 0) tmpdeque.push_back(addforward); /* cout << "tmpdeque:"; copy(tmpdeque.rbegin(),tmpdeque.rend(),ostream_iterator<int>(cout,"")); cout << endl; */ int size = tmpvector.size(); int index=0; addforward=0; while (!tmpdeque.empty()) { int a = tmpdeque.front(); tmpdeque.pop_front(); if (index < size) { if (pos == 0) tmpvector[index] = a; else { addforward += a; tmpvector[index] += addforward; addforward = tmpvector[index] / 10; tmpvector[index] %= 10; } ++index; } else { addforward += a; if (addforward<10) tmpvector.push_back(addforward); else { tmpvector.push_back(addforward/10); tmpvector.push_back(addforward%10); } } /* cout << "tmpvector:" << a << "|"; copy(tmpvector.rbegin(),tmpvector.rend(),ostream_iterator<int>(cout,"")); cout << endl; */ } /* tmpvector.clear(); */ cout << endl; ++pos; ++mulit; } digits.swap(tmpvector); cout << "digits "<< i << "!:"; copy(digits.rbegin(),digits.rend(),ostream_iterator<int>(cout,"")); cout << endl; } int sum = 0; cout << power <<"! = "; for (vector<int>::reverse_iterator rit = digits.rbegin() ; rit != digits.rend() ; ++rit) { cout << *(rit); sum += *rit; } cout << "\n sum of digits " << sum << endl;