1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <iomanip>
using namespace std;
void programInfo();
void inputList(double arr[], int &count);
void printList(double arr[], int n, int &count);
void sortAscending(double arr[], int n, int &count);
int main()
{
double endProgram = 0;
const int size = 30;
double arr[size];
int count = 0;
int n = 0;
while(endProgram != -1 || endProgram != -1.0)
{
programInfo();
inputList(arr, count);
printList(arr, n, count);
sortAscending(arr, n, count);
cout << "\n";
cout << "Run program again? Enter -1 or -1.0 to end program."<< endl;
cin >> endProgram;
if (endProgram == -1 || endProgram == -1.0)
{
cout << "Thank you for using my program." << endl;
}
}
}
void programInfo()
{
cout << "Vishant's Statistical Calculator." << endl;
cout << "Please follow instructions carefully." << endl;
cout << "Enter one value at a time up to 30 values." << endl;
cout << "You must enter valid data or program will not work." << endl;
cout << "Enter -1 to signal end of data (-1 or -1.0)" << endl;
}
void inputList(double arr[], int &count)
{
count = 0;
char answer;
cout <<"Input at least three values minimum, thirty values maximum." << endl;
while (count < 30)
{
cout <<"Please enter a value." << endl;
cin >> arr[count];
count++;
if (count == 3)
{
cout <<"Do you want to stop inputting values? (y/n)" << endl;
cin >> answer;
if (answer == 'y')
{
break;
}
}
}
}
void printList(double arr[], int n, int &count)
{
cout <<"Here is the list of values entered:" << endl;
for (n = 0; n < count; n++)
{
cout << setw(8) << arr[n];
}
}
void sortAscending(double arr[], int n, int &count)
{
double temp;
for (n = 0; n < count; n++)
{
for (int i = 0; i < count - 1; i++)
{
if(arr[i] < arr[n])
{
temp = arr[n];
arr[n] = arr[i];
arr[i] = temp;
}
}
}
}
|