Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

this is my program,what's the problem?int main() {int a,b,s,n; float q; cin>>b; s=0; while(s14 years ago

OpenStudy (anonymous):

What language is this

OpenStudy (anonymous):

I'm working on visual C++

OpenStudy (anonymous):

at first glance, it looks correct. What is it doing wrong?

OpenStudy (anonymous):

oh wait, you're using n in the loop, but it wasn't initialized.

OpenStudy (anonymous):

you just need one loop. initialize n to 1, and in the while loop, add 1/n to s, then increase n by 1.

OpenStudy (rsmith6559):

s=s+q; would demote q from a float to an int, also.

OpenStudy (anonymous):

yes, that too :-)

OpenStudy (anonymous):

s should be a float or double.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!