The program is supposed to calculate factorials, but for some reason it doesn't output the right things and I can't figure out why.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "stdafx.h"
#include <iostream>
constint ArSize = 16; // example of external declaration
int main()
{
using std::cout;
double factorials[ArSize];
factorials[1] = factorials[0] = 1.0;
int i;
cout << factorials[1];
for (int i = 2; i < ArSize; i++)
factorials[1] = i * factorials[i-1];
for (i = 0; i < ArSize; i++)
cout << i << "! = " << factorials[i]<< std::endl;
return 0;
}
I'm sure the answer is staring me straight in the face, and I'm just too wrapped up in what I think is the mistake to see the real mistake. That is usually how this happens. :) I just got introduced to the for loops in this book (C++ Primer Plus 5th ed.) and am still learning about them.