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";
}
}
1
Expert's answer
2014-03-04T11:04:08-0500
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
Comments
Leave a comment