Cout printing something unexpected.

Hi guys,
I have recently started learning c++. I do however know java and some python. I decided to come up with a basic program that would do a times table and print it out as a table in the output. Here is the program that i have managed to create:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>

using namespace std;

int main()
{
    int itterations;
    int TimesTabley[1000];
    int TimesTablex[1000];
    int holder;
    int x = 0;
    int y = 0;
        cout << "How many itterations do you want the program to run?";
        cin >> itterations;

    for(int i = 0; i <= itterations; i++ )
    {
        TimesTabley[i] = i;
        cout << TimesTabley[i] << ' ';
    }
    cout << '\n';
    for(int z = 0; z <= itterations; z++ )
    {
            TimesTablex[0] = z;
            cout << z << ' ';
    }
    for (int a = 0; a <= itterations; a++)
    {

        for (int b = 0; b<= itterations; b++)
        {
            holder = TimesTablex[a]*TimesTabley[b];
            cout << holder << ' ';

        }
        cout << '\n';
    }
    cout << '\n';

}

This is what it outputs when I enter 10 when it requests the value.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
How many itterations do you want the program to run?10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10 0 10 20 30 40 50 60 70 80 90 100
0 2683288 5366576 8049864 10733152 13416440 16099728 18783016 21466304 24149592
26832880
0 2684540 5369080 8053620 10738160 13422700 16107240 18791780 21476320 24160860
26845400
0 2684796 5369592 8054388 10739184 13423980 16108776 18793572 21478368 24163164
26847960
0 0 0 0 0 0 0 0 0 0 0
0 256 512 768 1024 1280 1536 1792 2048 2304 2560
0 -2 -4 -6 -8 -10 -12 -14 -16 -18 -20
0 256 512 768 1024 1280 1536 1792 2048 2304 2560
0 5062280 10124560 15186840 20249120 25311400 30373680 35435960 40498240 4556052
0 50622800
0 0 0 0 0 0 0 0 0 0 0
0 2683892 5367784 8051676 10735568 13419460 16103352 18787244 21471136 24155028
26838920


Process returned 0 (0x0)   execution time : 1.913 s
Press any key to continue.
 

I do not understand where it is getting these ridiculous numbers from. I wrote this program the other day and it was working fine. I reopened it again today because i wanted to try and make the table look neater. I did not change a thing and it would start printing out results like I have pasted.
If anyone has any ideas on what is going on please let me know.
I am using CodeBlocks as my c++ IDE.
Thanks for your help.
The "ridiculous numbers" are simply uninitialised variables.
Array TimesTablex is not assigned any value apart from element [0] which is set to itterations.

Actually, I don't see that the arrays are necessary at all, maybe the table could be printed out without them?
Last edited on
Topic archived. No new replies allowed.