Deleting previous text in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Schmatzy
    New Member
    • Jul 2007
    • 7

    Deleting previous text in C++

    hi i have a switch loop and i was wondering how i could delete the previous text when it loops
    this is my code
    [code=c]
    loop: int Answer;
    std::cout << "Enter a number of your choice. 11 or 12 ";
    std::cin >> Answer;
    switch (Answer)
    {
    default:
    goto loop;
    break;
    case 11:
    std::cout << "text";
    break;
    case 12:
    std::cout << "text";
    break;
    }
    [/code]
    if the loop happens it just copies the "Enter a number of your choice. 11 or 12 "; and the previous one is still there so how do i make it delete the old one?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Schmatzy. Welcome to TSDN!

    I'm going to go ahead and move this thread to the C++ forum, where one of our resident Experts will be more likely to be able to help you out.

    Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

    Comment

    • Schmatzy
      New Member
      • Jul 2007
      • 7

      #3
      ok i dunno anything about this forum either so thanks

      Comment

      • Schmatzy
        New Member
        • Jul 2007
        • 7

        #4
        its not even close to the entire code its just that section

        Comment

        • ilikepython
          Recognized Expert Contributor
          • Feb 2007
          • 844

          #5
          Originally posted by Schmatzy
          hi i have a switch loop and i was wondering how i could delete the previous text when it loops
          this is my code
          [code=c]
          loop: int Answer;
          std::cout << "Enter a number of your choice. 11 or 12 ";
          std::cin >> Answer;
          switch (Answer)
          {
          default:
          goto loop;
          break;
          case 11:
          std::cout << "text";
          break;
          case 12:
          std::cout << "text";
          break;
          }
          [/code]
          if the loop happens it just copies the "Enter a number of your choice. 11 or 12 "; and the previous one is still there so how do i make it delete the old one?
          Eww goto, how awful. Your code could be easily rewritten without the use of goto but that's off topic.

          The only two ways I know of are:
          [code=cpp]
          system("cls");
          clrscr();
          [/code]
          Both make your code un portable, though. Also, clrscr() isn't part of the C++ standard.

          Comment

          • Rasputin
            New Member
            • Jun 2007
            • 33

            #6
            Originally posted by ilikepython
            Eww goto, how awful.
            I must share this: I was TAUGHT AT SCHOOL to use goto in VB.

            At times some profs really have the skills to ruin you...

            Comment

            • Hunderpanzer
              New Member
              • Jul 2007
              • 60

              #7
              I'm always wanting to learn...

              What's wrong with goto ? What are it's flaws ?

              Comment

              • Meetee
                Recognized Expert Contributor
                • Dec 2006
                • 928

                #8
                Use of goto is discouraged because it makes your code harder to read and maintain. This is something I have read on one site

                This doesn't come up often, but sometimes, SOMETIMES a goto is necessary.
                SOMETIMES a GOTO isn't necessary, but it's a better alternative.

                If you have to use a goto, remember these rules:
                Rule #1 with a goto: NEVER JUMP BACKWARD. Jumping backward is the hardest code to read,
                you can easily replace this with a do { } while(); or other loop construct.

                Rule #2 DO NOT JUMP FAR OR OUT OF THE FUNCTION! Don't jump functions or jump too far
                from the goto, this starts to create messy and unreadable code.

                Rule #3 Make your label jump names IN ALL CAPS and make them SELF EXPLANATORY
                i.e. don't name them X or Y name them like EXIT_ON_BREAK:

                Regards

                Comment

                • Schmatzy
                  New Member
                  • Jul 2007
                  • 7

                  #9
                  Well, I am a beginner and i just learned about looping. I'm going more into loops right now.

                  Comment

                  • Schmatzy
                    New Member
                    • Jul 2007
                    • 7

                    #10
                    But please try to stay on the topic.

                    Comment

                    • Hunderpanzer
                      New Member
                      • Jul 2007
                      • 60

                      #11
                      Originally posted by zodilla58
                      Use of goto is discouraged because it makes your code harder to read and maintain. This is something I have read on one site

                      This doesn't come up often, but sometimes, SOMETIMES a goto is necessary.
                      SOMETIMES a GOTO isn't necessary, but it's a better alternative.

                      If you have to use a goto, remember these rules:
                      Rule #1 with a goto: NEVER JUMP BACKWARD. Jumping backward is the hardest code to read,
                      you can easily replace this with a do { } while(); or other loop construct.

                      Rule #2 DO NOT JUMP FAR OR OUT OF THE FUNCTION! Don't jump functions or jump too far
                      from the goto, this starts to create messy and unreadable code.

                      Rule #3 Make your label jump names IN ALL CAPS and make them SELF EXPLANATORY
                      i.e. don't name them X or Y name them like EXIT_ON_BREAK:

                      Regards


                      Thanks zodilla, I'll keep that in mind

                      Comment

                      Working...