1. I am working on a program. the program needs to determine mean of a group of numbers. I know how to find mean but I do not express mathematically.

2. ** REGISTER to REMOVE This Ad On The Site!! **
3. all depends what language really but it should look something like this

Code:
while list is not at end
{
total = total + number
total_numbers = total_numbers + 1
}
mean = total / total_numbers
that should give you an idea of what you should be doing.

4. thanks that will help

5. Don't forget to check to make sure the list is not "0" entries long, otherwise your program will try to divide by zero and most likely crash.

6. Originally Posted by nsap
Don't forget to check to make sure the list is not "0" entries long, otherwise your program will try to divide by zero and most likely crash.

If it's zero entries the loop would never start

7. indeed the loop would never start and it would jump to the line
Code:
mean = total / total_numbers
which would then divide by zero causing death, flooding and lots of other horrible things to happen.

8. Originally Posted by 4play
indeed the loop would never start and it would jump to the line
Code:
mean = total / total_numbers
which would then divide by zero causing death, flooding and lots of other horrible things to happen.
Yes you are correct. I figured it wouldn't throw an exception since it's 0/0 but it still doesn't like the fact that you are dividing by zero.

9. but let's be serious here

here's a simple c++ application that does it

http://pastebin.com/m109fe83c

Code:
//This application will calculate the average of X numbers

#include <iostream>    // So that we can input and output text
#include <iomanip>    // So that we can manipulate the outputted text
#include <stdlib.h>    // So that we can use cls to clear the screen
using namespace std;// So that we don't have to type std:: in front of commands such as cin and cout

void title()
{

cout << ":::::'###::::'##::::'##:'########:'########:::::'###:::::'######:::'########:::" << endl;
cout << "::::'## ##::: ##:::: ##: ##.....:: ##.... ##:::'## ##:::'##... ##:: ##.....::::" << endl;
cout << ":::'##:. ##:: ##:::: ##: ##::::::: ##:::: ##::'##:. ##:: ##:::..::: ##:::::::::" << endl;
cout << "::'##:::. ##: ##:::: ##: ######::: ########::'##:::. ##: ##::'####: ######:::::" << endl;
cout << ":: #########:. ##:: ##:: ##...:::: ##:. ##::: #########: ##::. ##:: ##...::::::" << endl;
cout << ":: ##.... ##::. ## ##::: ##::::::: ##::. ##:: ##.... ##: ##::: ##:: ##:::::::::" << endl;
cout << ":: ##:::: ##:::. ###:::: ########: ##:::. ##: ##:::: ##:. ######::: ########:::" << endl;
cout << "::..:::::..:::::...:::::........::..:::::..::..:::::..:::......::::........::::" << endl;
cout << endl;
cout << endl;
}
int main()
{
int mark;
double average;
int total = 0;
int count = 0;
int max;
char yn;

do
{
system("cls");
title();

cout << "How many numbers do you want in your average? ";
cin >> max;
cout << endl;
if (max < 1 || max > 100)
{
cout << "Your answer was either smaller than 1 or bigger than 100, program will now terminate" << endl;
return 0;
}

cout << "Please, enter " << max << " marks, and this application will calculate the average." << endl;

//Asks for a mark "max" times
for (count = 1; count <= max; count++)
{
cout << "Enter mark #" << count << " : ";
cin >> mark;
if (mark < 0 || mark > 100)
{
cout << "Invalid mark, please enter a mark between 0 and 100." << endl;
--count;
}
else
total = total + mark;
}

//Calculates the average
average = total / max;

//Displays the average of the 10 marks
cout << endl;
cout << endl;
cout << showpoint << setprecision(2) << fixed;
cout << "The average of the 10 marks is of " << average << " ." << endl;
cout << "Would you like to calculate another average? (y/n): ";
cin >> yn;
}
while (yn != 'n');
return 0;
}
i just made it real fast, what it does is that it asks for how many number you want in your average, and it loops the adding, at the end it divides by the ammount of numbers there was.

If you need more help, pm me

10. Use Matlab dude.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•