[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Needs help in loop

Posted on 2011-02-19
7
Medium Priority
?
355 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

650 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