Statistical Calculator help

So I am supposed to make a calculator that calculate the mean, median, and standard deviation of a list of values. This is what I have so far. The program lets the user enter 20 values, but I don't how to get the sentinal loop to signal the end of entering data. Also, after entering the values I get a runtime error.


#include <iostream>
#include <string> //any string work include string library

using namespace std;
//prototype section
void programInfo();
void inputList(double values[], int MAX_HOURS);
//void printList(double values[], int n, int valuesPerLine);
void sortDescending(double values[], int n);
double avgList(double values[], int n);
//double stdDev(double values[], int n);
//double medSortList(double values[], int n);
//void printStats(double max, double avg, double std);

int main()
{
const int MAX_VALUES = 20;
double values[20];
int n = 0;
int valuesPerLine = 0;
double max = 0;
double avg = 0;
double med = 0;
double std = 0;
string again = "yes";
int count = 0;
int values1 = MAX_VALUES;



while (again == "yes")
{

programInfo();
inputList(values, MAX_VALUES);
// printList(values, n, valuesPerLine);
sortDescending(values, n);
avgList(values, n);
// stdDev(values, n);
// medSortList(values, n);
// printStats(max, avg, std);


cout << "Do you want to run again? (yes or no)" << endl;
cin >> again;
}

cout << "Author: Edwin Trinh\n";

return 0;
}

//definitions section
void programInfo()
{
cout << "Edwin's statistical calculator." << endl;
cout << endl;
cout << "Please follow instruction carefully." << endl;
cout << "Enter a value at a time (at least 3 to up to 20)." << endl;
cout << "You must enter valid data or the program will not work." << endl;
cout << "Enter -1 to signal end of data (-1 or -1.0)." << endl;
cout << endl;
}

void inputList(double values[], int MAX_VALUES)
{
int values1 = MAX_VALUES;

for (int count = 0; count <= values1 - 1; count = count + 1)
{
cout << "Enter values: " << endl;
cin >> values[count];
}
}

void sortDescending(double values[], int n)
{
int temp;
int count = 0;
for (count = 3; count >= n; count++)
{
for (count = 0; count = n - 1; count++)
{
if (values[count] > values[count - 1])
temp = values[count];
values[count - 1] = values[count];
values[count] = temp;
}
}
}

double avgList(double values[], int MAX_VALUES)
{
int count;
double totalValues = 0;
double avg;

for (count = 0; count <= MAX_VALUES - 1; count = count + 1)
{
totalValues = totalValues + values[count];
}

avg = totalValues / MAX_VALUES;
return avg;
}
Last edited on
So I got the sentinel loop to end the inputting data and print the values as well, except it is print out a bunch of weird values and not the ones that I input. Is there something wrong with my printList code?


#include <iostream>
#include <string> //any string work include string library
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;
//prototype section
void programInfo();
void inputList(double values[], int MAX_HOURS);
void printList(double values[], int n, int valuesPerLine, int count);
//void sortDescending(double values[], int n);
//double avgList(double values[], int n);
//double stdDev(double values[], int n);
//double medSortList(double values[], int n);
//void printStats(double max, double avg, double std);

int main()
{
const int MAX_VALUES = 20;
double values[20];
int n = 0;
int valuesPerLine = 0;
double max = 0;
double avg = 0;
double med = 0;
double std = 0;
int count = 0;
int values1 = MAX_VALUES;


programInfo();
inputList(values, MAX_VALUES);
printList(values, n, valuesPerLine, count);
// sortDescending(values, n);
// avgList(values, n);
// stdDev(values, n);
// medSortList(values, n);
// printStats(max, avg, std);


cout << "Author: Edwin Trinh\n";

return 0;
}

//definitions section
void programInfo()
{
cout << "Edwin's statistical calculator." << endl;
cout << endl;
cout << "Please follow instruction carefully." << endl;
cout << "Enter a value at a time (at least 3 to up to 20)." << endl;
cout << "You must enter valid data or the program will not work." << endl;
cout << "Enter -1 to signal end of data (-1 or -1.0)." << endl;
cout << endl;
}

void inputList(double values[], int MAX_VALUES)
{
int count = 0;

cout << "Enter a value: " << endl;
cin >> values[count];

while (values[count] != -1)
{
values[count] = MAX_VALUES;
count++;
cout << "Enter a value: " << endl;
cin >> values[count];
}

}

void printList(double values[], int n, int valuesPerLine, int count)
{
for (count = 0; count <= 20; count++)
cout << values[count];
}
Last edited on
Topic archived. No new replies allowed.