Cin in while loops

This is a discussion on Cin in while loops within the C++ Programming forums, part of the General Programming Boards category; Hi trying to teach myself C++ I have only learnt about control structures, so that means no Functions or Arrays ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    62

    Cin in while loops

    Hi trying to teach myself C++ I have only learnt about control structures, so that means no Functions or Arrays or Class's (don't mean I dont know all about C++ though)
    Anyway in just a basic way that dont use BOOL, or anything else.

    I make it ask the user ask for two numbers, but say i want to break out of the loop, it still ask for the second number, before I can break out of it.
    What would be the correct structured way of doing this please? I am going bold here. and the sad thing is this is just the easy stuff.
    thanks

  2. #2
    Registered User
    Join Date
    Feb 2004
    Posts
    127

    Re: Cin in while loops

    Originally posted by chrismax2


    I make it ask the user ask for two numbers, but say i want to break out of the loop, it still ask for the second number, before I can break out of it.
    What would be the correct structured way of doing this please? I am going bold here. and the sad thing is this is just the easy stuff.
    thanks

    sorry but i didnt get you .. what is the program you want to write

    anyway i will try to analyze your problem as i understood form your words
    you want to break from a loop if and only if there are two numbers
    what do u mean by two numbers .. two digits or two whole number s.. i dont know what u really want anyway if u mean two numbers do u want to break from loop on entering specific numbers or generally on any two numbers entry?

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    It really depends on your code. You should probably post what you have so far, since there are many ways of doing what you are trying to do. In general, a break; will break out of a while loop, but there may be other issues in your code that make it not a good solution.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin problem
    By mikahell in forum C++ Programming
    Replies: 12
    Last Post: 08-22-2006, 12:14 PM
  2. getline(function)??
    By dac in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2006, 12:42 PM
  3. cin not allowing input after first use of function
    By Peter5897 in forum C++ Programming
    Replies: 5
    Last Post: 01-31-2006, 06:29 PM
  4. Overriding Cin with Cout
    By Tainted in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2005, 03:57 PM
  5. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21