445,918 Members | 2,240 Online Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

# Program goes into infinite loop

 P: 3 first thanks for every one who helps me... guys..I have to do program that count the value of Pi. where pi= 4( 1-(1/3)+(1/5)-(1/7)+((-1)^n/(2n+1)) I did the program but I have problems ...actually I want to learn c++ and this is the frist time for me with this program this is my code that I did Expand|Select|Wrap|Line Numbers #include  #include  #include  using namespace std;   int main() {   double n,p; char ans; do { cout<< " plz enter the value of N \n "; cin>> n; p = pow(-1,n)/(2*n + 1); cout<<" The Value Of Pi is " << "  " << p <>ans;     getch(); return(0); } I have also problem with while loop ... I did try to solve the problem but I could not ... Mar 11 '07 #1
5 Replies

 P: 93 first thanks for every one who helps me... guys..I have to do program that count the value of Pi. where pi= 4( 1-(1/3)+(1/5)-(1/7)+((-1)^n/(2n+1)) I did the program but I have problems ...actually I want to learn c++ and this is the frist time for me with this program this is my code that I did #include #include #include using namespace std; int main() { double n,p; char ans; do { cout<< " plz enter the value of N \n "; cin>> n; p = pow(-1,n)/(2*n + 1); cout<<" The Value Of Pi is " << " " << p <>ans; getch(); return(0); } I have also problem with while loop ... I did try to solve the problem but I could not ... You seemed to have made an error. the coode is wrong i think. How about this. Expand|Select|Wrap|Line Numbers #the headers.   int main() {   do {     // Pi calculations here        cout<<" The Value Of Pi is " << "  " << total <>ans;      if ((ans='y') || (ans='Y'))         continue;      else          return 0;   } while(true);   return 0; } Mar 11 '07 #2

 P: 3 thank you my friend ... but I still have the problem .... the program does not work .. Mar 12 '07 #3

 Expert Mod 2.5K+ P: 4,677 thank you my friend ... but I still have the problem .... the program does not work .. What's the problem? Did that change anything - and if so, what? Mar 12 '07 #4

 P: 3 ok .. I will tell you what the problem is exactly... I can run the program but in the last part when the user finish using the program he must be shown message if he wants to continue or not... actuallt the message can be shown but when I click (N) means no the program gives me uninfinite loooooooooooooop.. and I can't control it ... Mar 12 '07 #5

 Expert 2.5K+ P: 3,652 At the end, the person who gave you your full solution put ans='y' and ans='Y' These are, of course, assignment operations and not comparison operations. You need to use == to do this. Mar 12 '07 #6 