Ask your own question, for FREE!
Computer Science 16 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!
Latest Questions
Breathless: Spooky witch but cute
6 hours ago 3 Replies 0 Medals
Arriyanalol: help
6 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
9 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
8 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
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!