# Need help with project

• 06-19-2006
chrisa777
Need help with project
Here is the project im working on, im having a hard time figuring out an algorithm that will read the minimum and maximum values. Also when i am confused about the end of input signal(cntl+Z). My instructor also tells me that the program should instantly print the output and that i dont have to hit enter once I use it. I think he is completely wrong about this but I am not sure. My program also keeps assigning ^Z a numerical value.

Project description:

Design and implement a C++ program that works as follows.

First read a sequence of integer values. Stop reading values when the user enters the end-of-input signal, which is usually a <Ctrl-D> or <Ctrl-Z> combination on most computers.

Then print the following statistics:

* the total number of values that were entered
* the number of times the value 0 appeared
* the number of positive values
* the number of negative values
* the number of even values
* the number of odd values
* the minimum value
* the maximum value
* the sum of all the values
* the average of all the values (as a floating point number)
* the product of all the values (as a floating point number)

Your program should correctly handle unusual cases such as when all the values are negative, or all the values are positive, or the total number of values entered is 0.

The only library your C++ program may include is <iostream>.

Here is a sample run. The user input is shown in boldface red.
Enter value: 3
Enter value: 6
Enter value: 12
Enter value: -2
Enter value: -5
Enter value: -8
Enter value: 7
Enter value: 1
Enter value: 2
Enter value: 5
Enter value: <Ctrl-Z>

Number of values = 10
Number of zero values = 0
Number of positive values = 7
Number of negative values = 3
Number of even values = 5
Number of odd values = 5
Minimum value = -8
Maximum value = 12
Sum = 21
Average = 2.1
Product = -1209600
• 06-19-2006
laserlight
My suggestion is to store the numbers in a dynamic array. Once you do that, finding the minimum and maximum values should be rather easy.

Quote:

Also when i am confused about the end of input signal(cntl+Z).
In a way this allows you to simplify how you read the input values. You can use, say:
Code:

```int num; while (std::cin >> num) {         // ... }```
Then expect the user to break out of the otherwise infinite input loop.

Quote:

My instructor also tells me that the program should instantly print the output and that i dont have to hit enter once I use it. I think he is completely wrong about this but I am not sure.
I think your instructor is wrong too.

Quote:

Your program should correctly handle unusual cases such as when all the values are negative, or all the values are positive, or the total number of values entered is 0.
Another thing you may want to consider is what if invalid input is entered, e.g. an alphabetic character.
• 06-19-2006
Salem
• 06-19-2006
chrisa777
sorry this was my effort so far

Code:

```#include <iostream> using namespace std; void main() {         int input,int positive=0,int negative=0;         int odd=0,int even=0,int total_zeros=0,int total_numbers=0;         while (!cin.eof())         {         cout <<"enter value:\n";         cin >>input;         cout <<"enter value:\n";         cin >>input;             if ((input%2)==0)     even ++;         else         odd ++;             if (input >= 0)     positive ++;         else         negative ++;                 if (input ==0)         total_zeros ++;         else         total_numbers ++;         }                 cout <<"positive"<<positive<<endl;         cout <<"negative"<<negative<<endl;         cout <<"even"<<even<<endl;         cout <<"odd"<<odd<<endl;     cout <<"total zeros"<<total_zeros<<endl;     }```
• 06-19-2006
chrisa777
In a way this allows you to simplify how you read the input values. You can use, say:

Code:

```int num; while (std::cin >> num) {         // ... }```
when i use this method it doesnt recognize the first number i input, it does recognize all the subsequent ones. should i put the cin>>input inside the brackets of the loop?
• 06-19-2006
Daved
It might be because you have "cin >>input" twice in your program above. The only place that should be is inside the while control: while (cin >> input).