View Single Post
  #1 (permalink)  
Old June 10th, 2006, 01:03 AM
Prashant Sahni Prashant Sahni is offline
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pleeeeeeeeeeeeeez fix it!!!

Hi guys, i m having a problem in the following source code. Please see if you can help.Thanks a lot.

#include<iostream>
#include<iomanip>
#include<cctype>
using namespace std;
int main()
{
    char response='y';
    int num,sum=0;
    do{
        cout<<"Enter a number: ";
        cin>>num;
        sum+=num;
        cout<<"Do you want to enter another number?(y/n) ";
        cin>>response;
        response=tolower(response);
        while((response!='y')||(response!='n'))
        {
            cout<<endl<<"Please enter y to continue or n to end. ";
            cin>>response;
        }
    }while(tolower(response=='y'));

    cout<<endl<<"The sum of numbers that you entered is "<<sum<<"."<<endl;

    return 0;
}

When executed, the program enters an infinite loop (i m clueless about that!!).
This was compiled on VC++ 6.0. Make appropriate changes for your compiler.
Pleeeeeeeeeeeeeeeeeeeeeeez help!

Reply With Quote