# Help Help Help!!!

• 06-30-2009
Woot
Help Help Help!!!
I have a problem i can't seem to solve
Combining While Loops and If Statements
Write a program that reads a series of numbers (doubles) from the user, then prints the mean and the
range.
Notes:
• You do not know ahead of time how many numbers will be in the list.
• When you want to stop entering numbers, enter control‐Z.
• The range is the difference between the lowest and the highest number.
• The numbers will be in the range of 0.0 to 100.0. Ignore any numbers outside of this range.

this is my prompt so far. The average is only the last number not all the cins combine between 0 and 100

Code:

```#include <iostream> #include <string> using namespace std; int main () {         double n, sum = 0, count = 0;                 while(cin >> n)         {cin >> n;                 if  ((n >= 0.0) && (n <= 100.0))                 {                         ++count;                         sum += n;                        }                 else if (n == '^Z') break;                                 else                 {                         cout << "out of range: ignored.\n";                 }         }                 cout << "The average is " << sum / count << endl;                 }```
• 06-30-2009
tabstop
You've got too many read statements. (Edit: That is to say, you've got a read statement in your while condition, plus one at the top of the loop.)
• 06-30-2009
Woot
how do i fix this then?
• 06-30-2009
tabstop
• 06-30-2009
Woot
which ones are the extra read statment
• 06-30-2009
tabstop
Quote:

Originally Posted by Woot
which ones are the extra read statment

So, trace through your program by hand. Take a list of numbers as input, say "1 47 36 29 86 55 ^Z" and see what happens as your program executes.
• 07-01-2009
legit
Do you know what your read statements are? I somehow come to the conclusion that you haven't been paying attention in class. :P
• 07-01-2009
WatchTower
The question is do you know which one is in the expression and which one is not?
Which one are you using to terminate the loop and which one is not used to terminate the loop?
• 07-01-2009
laserlight
This is wrong:
Code:

`else if (n == '^Z') break;`
The purpose of the instruction to "enter control‐Z" is to simulate end of file, and when end of file is encountered, (cin >> n) evaluates to false, terminating the loop.
• 07-01-2009
hk_mp5kpdw
FYI, from the forum guidelines:
Quote:

Tips for Efficient and Successful Posting

1. Don't use all caps.

2. Use descriptive subject lines. Do not put URGENT!, or NEED HELP NOW, etc. in your title; it will not make people look at it any faster. Doing this makes many old time helpers on this board not look at the post at all.
Help Help Help!!! does not qualify as a descriptive subject line.
• 07-02-2009
Woot
can you delete a board post?
• 07-02-2009
sean
We generally don't delete posts because they can be useful for future readers. We'll usually delete inappropriate comments, though.