473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1.                 loop:         int Answer;
  2.     std::cout << "Enter a number of your choice. 11 or 12 ";
  3.     std::cin >> Answer;
  4.     switch (Answer)
  5.     {
  6.                          default:
  7.                                goto loop;
  8.                                break;
  9.                          case 11:
  10.                                std::cout << "text";
  11.                                break;
  12.                          case 12:
  13.                                std::cout << "text";
  14.                                break;
  15.                 }
  16.  
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?
Jul 22 '07 #1
10 2007
pbmods
5,821 Expert 4TB
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.
Jul 22 '07 #2
ok i dunno anything about this forum either so thanks
Jul 22 '07 #3
its not even close to the entire code its just that section
Jul 22 '07 #4
ilikepython
844 Expert 512MB
hi i have a switch loop and i was wondering how i could delete the previous text when it loops
this is my code
Expand|Select|Wrap|Line Numbers
  1.                 loop:         int Answer;
  2.     std::cout << "Enter a number of your choice. 11 or 12 ";
  3.     std::cin >> Answer;
  4.     switch (Answer)
  5.     {
  6.                          default:
  7.                                goto loop;
  8.                                break;
  9.                          case 11:
  10.                                std::cout << "text";
  11.                                break;
  12.                          case 12:
  13.                                std::cout << "text";
  14.                                break;
  15.                 }
  16.  
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:
Expand|Select|Wrap|Line Numbers
  1. system("cls");
  2. clrscr();
  3.  
Both make your code un portable, though. Also, clrscr() isn't part of the C++ standard.
Jul 23 '07 #5
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...
Jul 23 '07 #6
I'm always wanting to learn...

What's wrong with goto ? What are it's flaws ?
Jul 23 '07 #7
Meetee
931 Expert Mod 512MB
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
Jul 23 '07 #8
Well, I am a beginner and i just learned about looping. I'm going more into loops right now.
Jul 23 '07 #9
But please try to stay on the topic.
Jul 23 '07 #10
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
Jul 23 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stephen | last post by:
I've got a datagrid with a remove button and I would like to add some code in the code behind page so as whenthe button is clicked the corresponding row in the datagrid is removed. The Datagrid is...
6
by: Matan Nassau | last post by:
Hello. i have a composite which i want to delete. this is a composite which represents a boolean expression (see a previous post of mine with more details at...
6
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application...
8
by: shandra | last post by:
I have a file I need to delete or truncate. I tried using the KILL command in VB6. I tried using the file.delete command in VB.net. I tried manually deleting, renaming, and copying over the...
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
42
by: Avon | last post by:
Hello there. I have a problem regarding node deletion in singly-linked lists in C. What happens is that I can't hold the previous node efficiently. Here is the code I use. struct lista *search...
2
by: helraizer1 | last post by:
Hi folks, I have a file for my chatbox called data.line, which the posts are in the layout CHATBOXTEXT 7 username=helraizer 1202416953
4
by: MiziaQ | last post by:
Hey, I'm using the following code to write entries to a data file and then read them in an msflexgrid. I now would like to add code under a delete button to use the table(grid) to delete rows from...
4
Thekid
by: Thekid | last post by:
Hi, how can I get this Perl script to save the log without automatically deleting the previous logs? It only saves the new one: print '> Hello Kid ' . $ENV{'USER'} . '.' . "\n";...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.