Solved

repeat...until

Posted on 1998-11-18
5
204 Views
Last Modified: 2010-04-01
Is there a way to do a repeat - until statement?
ie..

repeat
      cout<<"is this bob?"<<endl;
      cin>>answer;
until
      answer='y'      


something like that....?
0
Comment
Question by:yaelie
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 0 total points
ID: 1178139

do {
     cout<<"is this bob?"<<endl;
     cin>>answer;
} while !(
     answer =='y'
     )

use ! (not) on the end condition
note == for comparison (otherwise you are assigning 'y' to answer)
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1178140
Oops, last bracket should have ; after it

do {
          cout<<"is this bob?"<<endl;
          cin>>answer;
     } while !(
          answer =='y'
          ) ;
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178141
That is not exactly right.  The biggest problem is that it is formatted weirdly : - ).  the second problem is that "!" outside of the "()"  What you realy want is a != inside, like

do {
         cout<<"is this bob?"<<endl;
         cin>>answer;
} while (answer != 'y' ) ;
0
 
LVL 1

Author Comment

by:yaelie
ID: 1178142
thank you...
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1178143
Oops, formatting messed me up

Thanks for the correction nietod
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now