I have made a program which the user will input the total inputted numbers and record it as an array, sort the biggest and smallest number, post the original inputted number, reverse the original's order, and lowest to high order. I have done the recording, sorting, however, when the program post the original number, reverse order, and high to low, it is not complete. It is not posting the whole arrays. Please check my program and if it is possible point out the errors. Thank you so much.
#include <iostream>
#include <iomanip>
using namespace std;
void r3(double[], int&);
void Reverse(double[], int&);
int main()
{
int j;
cout << "Enter how many numbers to input : " ;
cin >> j;
double r1[j], temp[j];
for ( int i=0 ; i<j ; i++)
{
cout << "Enter #" << i + 1 << " : ";
cin >> r1[i] ;
temp[i]=r1[i];
}
cout<< endl;
r3(temp, j);
cout << endl;
Reverse(r1, j);
cout << "\nFrom Lowest To Highest" << endl ;
while (j-1>=0)
{cout << " " <<setw(5) << fixed << setprecision(1) << r1[j] << endl;
j--;}
system("pause");
return 0;
}
void r3(double r1[], int& j)
{
bool restart;
double highest, lowest, temp;
int i;
do
{
restart = false;
for ( i = 0 ; i < j; i++ )
{
if ( r1[i] < r1[i+1] )
{
temp = r1[i];
r1[i] = r1[i+1];
r1[i+1] = temp;
restart = true;
}
}
}
while ( restart == true );
highest = r1[0];
lowest = r1[j-1];
{
cout << "Highest inputted number : " << highest << endl;
cout << "\nLowest inputted number : " << lowest << endl;
}
}
void Reverse(double r1[], int& j)
{
int k = 0;
double r2[j];
cout << " Original\tReverse" << endl;
for (;k<=j+1;j--)
{
r2[k]=r1[j-1];
cout << " " <<setw(5) << fixed << setprecision(1) << r1[k]
<< " " <<setw(5) << fixed << setprecision(1) << r2[k] << endl ;
k++;
}
}