Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,271 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,442 people online right now. Registration is fast and FREE... Join Now!




Minimum, Maximum and Mean Determination

 
Reply to this topicStart new topic

Minimum, Maximum and Mean Determination

cnoobie
14 Oct, 2006 - 12:21 PM
Post #1

New D.I.C Head
*

Joined: 14 Oct, 2006
Posts: 1


My Contributions
Problem 1 - Min, Mean, Max

Write a program that reads in successive integer values from the user. The user will indicate termination of these values with the sentinel value 0 (zero). After the program has read in the values, the program will output the minimum value entered, the maximum value entered, and the mean (average) of the values entered (to two decimal places). If the user does not enter any numbers before entering 0, the program will display the message "No numbers were read".

Please enter some integers, and a 0 (zero) to terminate:
1 2 3 4 5 0
The minimum number entered was 1
The maximum number entered was 5
The mean of the numbers was 3.00
Press any key to continue . . .




Please enter some integers, and a 0 (zero) to terminate:
1 2 3 4 5 6 7 8 9 10 0
The minimum number entered was 1
The maximum number entered was 10
The mean of the numbers was 5.50
Press any key to continue . . .




Please enter some integers, and a 0 (zero) to terminate:
0
No numbers were read.
Press any key to continue . . .


You may assume that the user enters a valid integer.

okay that is what the assignment is


this is what i have so far and im totally lost

CODE

#include <iostream>
#include <cmath>
using namespace std;

int main ()

{
    int number;
    cout << "Please enter some integers, and a 0 (zero) to terminate:" <<endl;
    cout << endl;
    cin >> number;
    
    if (number == 0)
{
    cout << endl;
    cout << "No numbers were read." << endl;
    cout << endl;
}

    while (number !=0)
{
    int count;

    count ++;

}


    return 0;
}


edit: added [code] tags ~ jayman9
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Minimum, Maximum And Mean Determination
14 Oct, 2006 - 12:49 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
You can accomplish this with a few variables...one to hold the min, one for the max, one for input, a counter variable, and one to hold the sum of the numbers.

Take the input...for the first number entered, set the min and max equal to that as well, and assign the value to the sum variable. Increase the count by one. Take the next input...check if it's lower than the min, or higher than the max - if so, replace the appropriate variable. Add the value to the sum. Increase the count by one.

When a zero is entered, stop. Print out the max, min, divide the sum by the count, and print the mean.

If you wish, you can also use an array and sort, but the method described above will work easily enough.
User is offlineProfile CardPM
+Quote Post

jayhuang
RE: Minimum, Maximum And Mean Determination
15 Oct, 2006 - 04:10 PM
Post #3

New D.I.C Head
*

Joined: 11 Oct, 2006
Posts: 31


My Contributions
This is an easy assignment. All you need to know is set a variable to hold. It is much easier to use vector or array but I guess you haven't been taught about those yet.

Here is the easiest way. Use if statement. Just a route to you.


int max(0);

if (number > max) {
max = number;
}
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:50PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month