![]() |
|
#1
|
|||
|
|||
Combining While Loops and If StatementsPlease help. New assignment and I am totally lost on this. I was able to complete my last assignment, so thank you for everyone's help.
PLease see attached assignment. Thank you in advance. |
|||
|
#2
|
||||
|
||||
Re: New assignment - Lost on.Show us your work so far.
__________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
Re: New assignment - Lost on.Here is what I have so far, I am stuck with the "control "z"" break ordeal, and when the number is "out of range", how do you keep it from counting the out of range number in the equation.
Also, if you don't know how many numbers is going to be included, how do you do the The range is the difference between the lowest and the highest number? CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: New assignment - Lost on.Quote:
The cin stream can be tested for "eof" or other error conditions and the loop can be made dependent on the results. Here's a way to create a loop that terminates whenever a console "eof" character is entered. In fact the loop terminates whenever anything other than a numeric value is entered by the user: CPP / C++ / C Code:
Quote:
CPP / C++ / C Code:
Quote:
Code:
Regards, Dave Footnote: On Linux systems or other systems using the Bash shell, Ctrl-d is the console "eof" character. Ctrl-z is intercepted by the shell before it gets to your program and causes the process to go to background mode, so the assignment simply could not be carried out without a lot of other system-dependent stuff (setting the console to raw mode, for example). I think it's important for people to understand facts like this: defining behavior from console programs is operating-system dependent, compiler-dependent, and, in fact, shell-dependent. But I guess that's too much information for a beginning program class. Anyhow, I just thought I would mention it. Some day, some way, this may mean something to you, and, in fact may be important. Or, maybe, not. Oh, well... Last edited by davekw7x : 18-Oct-2009 at 13:28.
|
|
#5
|
|||
|
|||
Re: New assignment - Lost on.I am still confused. I made the changes you said, and it still doesn't work. Also, I don't get your last statement at all concerning the min and max
|
|
#6
|
|||
|
|||
Re: New assignment - Lost on.Here is what I have now, I still have the problem with the
" if you don't know how many numbers is going to be included, how do you do the The range is the difference between the lowest and the highest number?" CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
Re: New assignment - Lost on.Anyone? Need help please.
|
|
#8
|
||||
|
||||
Re: New assignment - Lost on.Quote:
Read the first number. Set min and max to this value. Then read the rest of the numbers replacing min/max as necessary. __________________
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: New assignment - Lost on.Quote:
CPP / C++ / C Code:
Quote:
Test the program and make sure the loop works the way you expect it to work. Then go back to my previous post. Write code that implements step 1. Write code that implements step 2. Write code that implements step 3. Code for steps 2 and 3 go inside the loop at the part where the current input has been validated. By "first time" I mean to do step 2 if count is equal to zero. This sets xmax and xmin equal to the first valid value. If count is not equal to zero, then do the comparisons to see whether xmin has to be changed and whether xmax has to be changed. Regards, Dave Footnote: The program that you posted works for me (with various compilers from Microsoft, Borland and GNU) on my Windows xp workstation as long as I follow instructions. (That is, I enter a bunch of numbers and then ctrl-z, it gives the expected results.) My example in this post just eliminated the superfluous, useless stuff that you put around the part that you need. In fact, the superfluous useless stuff that you added can make the program get "hung up" if the user enters a non-numeric something. That does not happen with my example. I'm not sure what, exactly, your assignment was. Anyhow... What compiler are you using? What operating system? What, exactly, doesn't work? In other words, what input did you give it and what did the program do? (Or, what did it not do that it should have done?) Last edited by davekw7x : 18-Oct-2009 at 21:21.
|
|
#10
|
|||
|
|||
Re: New assignment - Lost on.Quote:
Oh, wait...It's even in the Guidelines: for posting requests for help Quote:
I knew that sounded familiar! (Yes, I did read the Guidelines, once upon a time, and I appreciate your efforts.) Oh, well... Regards, Dave |
Recent GIDBlog
Problems with the Navy (Officers) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Circular Linked Queue Copy Constructor and Assignment Operator Not Working? | wc3promet | C++ Forum | 1 | 06-Oct-2008 03:00 |
| Assignment Operator and Pointer | Peter_APIIT | C++ Forum | 14 | 25-Sep-2007 05:36 |
| double concatenated dynamic list - different type assignment warning | dlp | C Programming Language | 11 | 01-Jun-2007 07:59 |
| Am I reading this assignment correctly? | earachefl | C++ Forum | 2 | 09-May-2006 09:39 |
| Not sure I understand this assignment.... | earachefl | C++ Forum | 7 | 05-May-2006 16:12 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The