Ok guys, need some help here. I want to turn in this assignment by the latest Wednesday.
I need to write a program that reads numbers out of a .dat file, into an array. Then it needs to find the standard devation, range, median, and average. I've got the code for the average done, thats easy. I'd need help with the code on the deviation. And, I need help on sorting the numbers. I cannot figure out how to sort the numbers from lowest to highest (or any way, for that matter). No matter what I try, no dice. I did look in my book, but I can't really do it the way they show it, as they are not taking the numbers in the arrays.
So, to clarify, I need to figure out how to sort the numbers. And still be able to access them of course. Here is the code I have, which does not work. No errors, just a BS number (like -9 trillion or something):
Code:
//sort.cpp sorts the index from lowest value to highest value
//
//Adam Holthaus
#include "stdafx.h"
#include <iostream>
using namespace std;
double sort(double index[], int esave)
{
//Initializing variable
int n, min, entry, edefine;
for(edefine = 0; edefine < esave; edefine++)
{
min = index[edefine];
n = edefine;
for(entry = edefine; entry < esave; entry++)
{
if(index[n] < min)
{
min = index[n];
n = entry;
}
}
index[n] = index[edefine];
index[edefine] = min;
}
return index[esave];
}
esave stands for the amount of numbers in the array. I kept track reading out of an array. index[] is my array, which already has the numbers in it. You can see what I did in the code...what's wrong.
I think it might be easiest if you made your own .dat file or .txt file.
Thanks guys.