64 747
Assignments Done
99,3%
Successfully Done
In September 2018

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


}


}

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

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions