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:
#include <iostream>
usingnamespace 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.
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?