Question #39047

Hi there! i am a newbie in C++. So i have these simple lines of codes written down:
when i run the program i get this (" Find: 0 "): before typing any number... My question is: where is 0 coming from?

]#./math
Find: 0 3
1
3
5
]#



#include<iostream>

using namespace std;

int An, n, number, r=1;


int main (void) {
cout << "Find "<<number<<" ";

cin>>number;


for (int n=1;n<=number; n++ ) {
An = n+(n-1)*r;

cout <<" "<<An<<" \n";


}


}

Expert's answer

Answer:
the zero is coming from number variable:
cout << "Find " << number << " ";

As the number variable is not initialized you will see:
1) in Debug mode - 0
2) in Release mode - some unknown number
LATEST TUTORIALS
APPROVED BY CLIENTS