Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (christos):

C++: I am trying to solve this problem: http://screencast.com/t/5qEYoyMHyo8 This is my code: http://pastebin.com/W46viXhC Can you please tell me why it gives an infinite loop ?

OpenStudy (christos):

@e.mccormick

OpenStudy (christos):

@dan815

OpenStudy (anonymous):

what exaclty is the error

OpenStudy (christos):

infinite loop

OpenStudy (anonymous):

#include<iostream> using namespace std; void sum() { int n; cout<<"Enter the number"; cin>>n; int sum=0; while(n>0) { sum+=n; --n; } cout<<"\n\nThe sum is"<<sum; } int main() { char ch; do { cout<<"\n \n DO you want to call the function"; cin>>ch; if(ch=='y') { sum(); } } while(ch!='n'); }

OpenStudy (e.mccormick):

@bhaskar.pathk that char ch eval needs some work to catch nNyY. The probkem states all four are needed. @Christos Did you try printing out n inside the loop to see what is happening to it? Or is it the other loop? I did not compile it to see which os going forever.

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!