![]() |
|
#1
|
|||
|
|||
Sample looping (do/while)Ok I'm having trouble doing a validation loop for part of a program I am doing using a do/while loop.
The code I have is: CPP / C++ / C Code:
Well, it works because it asks repeatedly the user for a number if it is invalid, but here is what I get: Quote:
When I enter a valid number (300 or 200 or whatever is valid) it still says "Invalid sales rep number, try again" and automatically goes to the customer after that. So, how could I fix this so it goes RIGHT to the customer number without repeating the invalid text when a valid number is entered? Sorry I am a bit rusty, I know this is very easy =\ |
|||
|
#2
|
|||
|
|||
Re: Sample looping (do/while)It's because you said to output "invalid ..." regardless of whatever the number is, valid or not. You have to make it so it processes the first answer and then decides whether to print that out or not.
consider changing it to something like this: CPP / C++ / C Code:
That'd probably work. Last edited by LuciWiz : 27-Mar-2006 at 11:43.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#3
|
||||
|
||||
Re: Sample looping (do/while)Quote:
A more compact and straight forward version of your code is: CPP / C++ / C Code:
__________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#4
|
||||
|
||||
Re: Sample looping (do/while)Sabin, Welcome back
Kobi __________________
It's actually a one time thing (it just happens alot). |
|
#5
|
|||
|
|||
Re: Sample looping (do/while)CPP / C++ / C Code:
I forgot that you needed to repeat the message inside =P Same with CPP / C++ / C Code:
Thanks for your feedback, I am forgetting too much from my C class hehe=] Hey Kobi thanks for the welcome, nice to see you and everyone else :] |
|
#6
|
|||
|
|||
Re: Sample looping (do/while)I came across something else that has stumped me sitting here for hours looking at it. I'm guessing it involves another loop of some sort.
Anyways, I made 2 sales reps with user input (for the 2 of course). Now, the thing that gets me is.. it says "allow the user to enter the data for any number of sales reps and display the 2 reports for that rep before prompting the user for the next sales rep." In which the 2 main reports I have completed.. but "allowing to enter as many as the user wants" is the thing that seems tricky to me. so lets say (without the validation/input code) my code for the report 1 is.. CPP / C++ / C Code:
I do not understand how the user can enter amounts of an "item number" and "quantity" and have it calculate the "Total Sale" (at the bottom of report) all at once. (This will show u I already have inputs) So for example my output for report1 is this: CPP / C++ / C Code:
The sample output my teacher gave me to test the validation/input was this: CPP / C++ / C Code:
Now, notice the testing input gave 3 different item numbers, quantitys, and prices. I need the user to enter exactly more than 1 of each of those... I'm basically thinking a loop is needed here, but I have not done any kinda loop like this before (i'm pretty sure i havent) yet my book does not explain loops in great detail... My 2nd report looks like this: CPP / C++ / C Code:
Again, I cannot get the "Total Sales" because I cannot figure out how to get the sample input shown above. Output for report2; CPP / C++ / C Code:
This prob isnt hard for most of you Thanks again, will be looking forward to comments. |
|
#7
|
||||
|
||||
Re: Sample looping (do/while)Quote:
Yeah, it happens ... It took me lots of time to understand the concept of a ... pointer and I still make silly mistakes, sometimes. Sabin, there is an excellent explanation about control flow at K&R "The C Programming Langauge" - and before anyone kills me for offering you to read a "C book" in a "C++" thread, let me say : It's the principal that matters. Once you understand for, if-else and while loops with one language, you will have no trouble will another (same level) language. See ya, Kobi __________________
It's actually a one time thing (it just happens alot). |
|
#8
|
||||
|
||||
Re: Sample looping (do/while)Quote:
What you probably want to do is after you enter a name, enter your Item#, Quantity, and Unit Prices for that sales rep. Load the data into a matrix (2d array). Then as you create the report, all your data is ready to go. __________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#9
|
|||
|
|||
Re: Sample looping (do/while)Yes, that can make the user input multiple times, instead of showing the "Rep" multiple times.
I was thinking about using functions, but I do not really see a use. I'm going to be working on this again after i get off work tonight,, gonna be a long day Thanks kobi/walt + everyone |
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ask looping | likeit | C Programming Language | 4 | 26-Jul-2005 19:49 |
| Signed Key Sample | thatsalok | C++ Forum | 0 | 06-Dec-2004 22:13 |
| Simple FLTK dialog box sample | cable_guy_67 | FLTK Forum | 4 | 02-Nov-2004 08:46 |
| for looping prob | Rosmayati | C Programming Language | 1 | 30-Jun-2004 11:39 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The