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 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void sortingNumbers (int valListInt[]){
int intNum1,intNum2;
int sorting;
for (intNum1 = 0; intNum1 < 10; intNum1++)
for (intNum2 = 0; intNum2 < 10; intNum2++)
if (valListInt[intNum2] > valListInt[intNum2 + 1]){
sorting = valListInt[intNum2];
valListInt[intNum2] = valListInt[intNum2 +1];
valListInt[intNum2 + 1] = sorting;
}
for (intNum1 = 0; intNum1 < 10; intNum1++)
cout << valListInt[intNum1] << endl;
}
void sortingNumbers (long valListLong[]){
int longNum1,longNum2;
long sorting;
for (longNum1 = 0; longNum1 < 10; longNum1++)
for (longNum2 = 0; longNum2 < 10; longNum2++)
if (valListLong[longNum2] > valListLong[longNum2 + 1]){
sorting = valListLong[longNum2];
valListLong[longNum2] = valListLong[longNum2 + 1];
valListLong[longNum2 + 1] = sorting;
}
for (longNum1 = 0; longNum1 < 10; longNum1++)
cout << valListLong[longNum1] << endl;
}
void sortingNumbers (double valListDouble[]){
int doubleNum1,doubleNum2;
double sorting;
for (doubleNum1 = 0; doubleNum1 < 10; doubleNum1++)
for (doubleNum2 = 0; doubleNum2 < 10; doubleNum2++)
if (valListDouble[doubleNum2] > valListDouble[doubleNum2 + 1]){
sorting = valListDouble[doubleNum2];
valListDouble[doubleNum2] = valListDouble[doubleNum2 + 1];
valListDouble[doubleNum2 + 1] = sorting;
}
for (doubleNum1 = 0; doubleNum1 < 10; doubleNum1++)
cout << valListDouble[doubleNum1] << endl;
}
void main()
{
int userMenu;
bool stoploop = false;
while (!stoploop){
cout << "Which numbers do you want to see sorted?\n";
cout << "1. Integers\n" << "2. Long Doubles\n" << "3. Doubles\n";
cout << "Enter your choice: ";
cin >> userMenu;
if (userMenu == 1){
int valListInt[] = {23,2,34,23,43,22,32,32,43,34};
sortingNumbers (valListInt);
cout << "Continue (y/n)? ";
char userAnswer;
cin >> userAnswer;
if (toupper(userAnswer) != 'Y')
stoploop = true;
} else if (userMenu == 2){
long valListLong[] = {7000,15,34,2373645,43,22,9392929294,46,32,111143};
sortingNumbers (valListLong);
cout << "Continue (y/n)? ";
char userAnswer;
cin >> userAnswer;
if (toupper(userAnswer) != 'Y')
stoploop = true;
} else if (userMenu == 3){
double valListDouble[] = {23.3847239,2.3974,34.183734,23.0,43.36381,22.3,32.0,32.1919,43.938363,34.38364};
sortingNumbers (valListDouble);
cout << "Continue (y/n)? ";
char userAnswer;
cin >> userAnswer;
if (toupper(userAnswer) != 'Y')
stoploop = true;
}
}
system("pause");
}
|