GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Aug-2008, 01:24
anonymous89 anonymous89 is offline
New Member
 
Join Date: Jun 2008
Posts: 3
anonymous89 is on a distinguished road

Ensure Correct Data Is Entered


Hi, can I know the coding for the below situation.

Basically, I want to ask the user to enter the desired data, for instance name. Then I proceed to ask the user to enter his age (between a certain range). The problem is that how do I prompt the user to reenter the correct data, while clearing the data that has been previously entered and displayed, and at the same time, make sure that his name is not cleared.

It goes something like this.................
__________________________________________________ _______________
Please enter your name: Jack Johnson

Please enter your age : 900

You entered over 100 years. Enter again.
__________________________________________________ _______________
Since data entered is not in the allowable range, prompt the user to enter again.
__________________________________________________ _______________
Please enter your name: Jack Johnson

Please enter your age :

__________________________________________________ _______________

All I know is that only one command can be used to clear the screen, ie, system("cls"). But if I use this, it will clear the first line as well.

Please help.
  #2  
Old 09-Aug-2008, 07:35
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 586
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Ensure Correct Data Is Entered


Quote:
Originally Posted by anonymous89
The problem is that how do I prompt the user to reenter the correct data, while clearing the data that has been previously entered and displayed, and at the same time, make sure that his name is not cleared.
I assume you are displaying output in text mode which means you are limited to centering, indenting, & orienting text vertically. Below are various comments:
  • There is little standardization of functions targeting console placement amongst the various compiler vendors. Since you have not mentioned what compiler or platform you are using, I cannot tell you the answer you are seeking.
  • Basically, you need to search through your documentation for functions for outputting text to a specific (x, y) coordinate. This will get around the problem where you are having to redisplay everything that is already on the screen.
  • If you cannot find such a function, upon the need to redraw the screen you will need to simply output everything that has already been displayed. You will need to retain all information which has been obtained from the user.
  • If you doing this for an assignment, you will need to weigh whether you are putting too much time into details which aren't critical to the overall purpose.
  #3  
Old 09-Aug-2008, 11:27
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Ensure Correct Data Is Entered


At a known point in the program, at the point of entering the age for example, one possibility after to clearing the screen is to redraw everything back to the age prompt. Something like this pseudo-code: (note this is only a suggestion, other ways are possible, as ocicat pointed out)

Code:
prompt name >> name flag = true DO prompt age >> age IF ( age is OOR ) // OOR=out of range clear screen output name prompt, display previous name input ELSE flag = false END CONDITIONS WHILE (flag)
For some, this might seem to be more hassle as it carries more variables and handling, but could potentially offer another idea. HTH
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory leak when nothing is happening... How can I even debug this ? Algar MS Visual C++ / MFC Forum 10 19-Nov-2007 07:17
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Strange C++ code memory leakage problem gaoanyu C++ Forum 7 04-Nov-2005 08:09
[GIM] Data Module - Contact dsmith C Programming Language 2 27-Jan-2005 16:30
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 15:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:15.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.