Answer to Question #39047 in C++ for Kerry

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";


}


}
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS