CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2016
    Posts
    1

    Help with looping [beginner]

    I am trying to make a program that asks you to enter some names and I want that program to loop the same thing until you press "control", then I want it to stop and just output all the names you entered...I made a boolean called exit that is false by default and I thought about something that when you press crtl you set it to be true and then that loop stops and just outputs names...also how to make a variable that can hold a lot of names(if you enter 10 then it will hold 10 or if you enter more it will hold more names in it)...I would be very grateful if someone could help me ... sorry for bad english, I may have some weird grammar mistakes

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,923

    Re: Help with looping [beginner]

    If you post your existing code, that would be helpful. Use code tags so that the code is easy to read. Go Advanced, select the formatted code and click '#'.

    Determining the state of the control key is non-trivial. It would be easier if your loop was terminated by eof (ctrl-z for keyboard input on Windows). To hold an unknown number of names then I would suggest using a vector. See http://www.cplusplus.com/reference/vector/vector/

    To enter a name consider using getline(). See http://www.cplusplus.com/reference/s...tring/getline/
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured