Solved

Needs help in loop

Posted on 2011-02-19
7
351 Views
Last Modified: 2012-05-11
Hi guys: Can any one plesae help me how to i stop the loop when the value in a char variable named anyletter is anything other than the letter Y (in either upper or lower case).

I try it first but dont know how to stop the loop. Thanks.

#include <iostream>
using namespace std;

int main()
{
      int number = 0;
      char anyletter = ' ';
      do
      {
            cout << number << endl;
            number +=1;
      }      while(number <=100 );
            system("pause");
            return 0;
}

0
Comment
Question by:mustish1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:andreizz
ID: 34934492
#include <iostream>
#include <ctype>
using namespace std;

int main()
{
      int number = 0;
      char anyletter = ' ';
      do
      {
            cout << number << endl;
            cout<<"Letter:";cin>>anyletter;
            if(isalpha(anyletter)&&(anyletter!='Y'||anyletter!='y'))
                 break;
            number +=1;
      }      while(number <=100 );
            system("pause");
            return 0;
} 

Open in new window


you need ctype for the isalpha test, u can remove that if you don't want to check it.
0
 

Author Comment

by:mustish1
ID: 34934501
I am using visual c++ 2010 it gives error on this line
#include <ctype>
0
 
LVL 4

Expert Comment

by:andreizz
ID: 34934515
#include <iostream>
#include <ctype.h>
using namespace std;

int main()
{
      int number = 0;
      char anyletter = ' ';
      do
      {
            cout << number << endl;
            cout<<"Letter:";cin>>anyletter;
            if(isalpha(anyletter)&&(anyletter!='Y'||anyletter!='y'))
                 break;
            number +=1;
      }      while(number <=100 );
            system("pause");
            return 0;
} 

Open in new window


or

#include <iostream>
using namespace std;

int main()
{
      int number = 0;
      char anyletter = ' ';
      do
      {
            cout << number << endl;
            cout<<"Letter:";cin>>anyletter;
            if(anyletter!='Y'||anyletter!='y')
                 break;
            number +=1;
      }      while(number <=100 );
            system("pause");
            return 0;
} 

Open in new window

0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

Author Comment

by:mustish1
ID: 34934517
its not showing any thing.

errorcp.jpg
0
 
LVL 4

Expert Comment

by:andreizz
ID: 34934559
#include <iostream>
using namespace std;

int main()
{
      int number = 0;
      char anyletter = ' ';
      do
      {
            cout << number << endl;
            cout<<"Letter:";cin>>anyletter;
            if(anyletter!='Y'&&anyletter!='y')
                 break;
            number +=1;
      }      while(number <=100 );
            system("pause");
            return 0;
} 

Open in new window


sorry, there wasn't the || operator but &&
try this and renember to print numbers you have to input Y or y else it stops.
0
 
LVL 4

Accepted Solution

by:
andreizz earned 500 total points
ID: 34934566
#include <iostream>
using namespace std;

int main()
{
      int number = 0;
      char anyletter = ' ';
      do
      {
            cout << number << endl;
            cout<<"Letter:";cin>>anyletter;
            if(isalpha(anyletter)&&anyletter!='Y'&&anyletter!='y')
                 break;
            number +=1;
      }      while(number <=100 );
            system("pause");
            return 0;
} 

Open in new window


this is final try it.
0
 

Author Closing Comment

by:mustish1
ID: 34934588
Thanks a lot.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Make the most of your online learning experience.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question