Hello everybody, I've just started my adventure with C++. I have a problem with this bit of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
using namespace std;
int main()
{
int x;
int y = 0;
int z;
cout<<"Number: ";
cin>> x;
cin.ignore();
for (int x; y < 11; z=x*y++) {
cout<< x << " X " << y << " = " << z <<"\n";
}
cin.get();
}
|
The main problem lies within these lines:
1 2 3
|
for (int x; y < 11; z=x*y++) {
cout<< x << " X " << y << " = " << z <<"\n";
}
|
What I want to recieve is a small chart that displays, for example:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
and so on till 3 x 10, but for any number I put in, say we'll name it "n" (so n * (numbers from 1-10) = proper result), but my compiler says the following:
|14|warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]|
and the results that I get in the running program are, well, quite unusual... I get something like that:
- I input number when it says "Number: "
- I press ENTER
- Program displays: VEEERY high number (not the one inputed) X (numbers from 1-10, as it should) = EVEN HIGHER number.
Can someone tell me what am I doing wrong? Like, any issue with the build of the loop, or the variables? Thanks a lot for any help.