Hey I'm new here to these forums and I'm in need of some help with my program. I'm supposed to write a program that will allow the user to enter up to 100 values into an array. The program will then count how many values were entered and display the number counted along with the actual values themselves. To top it off, the program then needs to sort the values in ascending order and display them back. Could anyone help me with my code please?
#include <iostream>
using namespace std;
int Function1(double []);
void Printarray(double [], int );
int main()
{
double array1[100];
int count;
count = Function1(array1);
cout<<"There were "<<count<<" numbers entered into the array."<<endl;
Printarray(array1, count);
int i;
int last = count - 2;
int first = 0, pass = 0;
bool sort = false;
double fntArray[count];
double temporary;
while (!sort)
{
sort = true;
for (i = first; i <= last; i++)
{
if (fntArray[i] > fntArray[i+1])
{
temporary = fntArray[i];
fntArray[i] = fntArray[i+1];
fntArray[i+1] = temporary;
sort = false;
}
}
last = last - 1;
pass++;
cout<<pass<<endl;
Printarray(array1, count);
}
return 0;
}
//This function counts the number of values entered by the user (up to 100) and then returns the number of values counted.
//
int Function1(double fntArray[])
{
int i = 0;
double somenumber = 0;
do
{
cout<<"Please enter a number to enter into the array or a negative number to stop."<<endl;
cin>>somenumber;
if (somenumber >= 0)
{
fntArray[i] = somenumber;
i++;
}
}while (i < 100 && somenumber >=0);
return i;
}
//This function prints each value entered by the user and returns the array of values to the main function.
//
void Printarray(double fntArray[ ], int size)
{ for (int j = 0; j < size ; j++)
{cout<<fntArray[j]<<endl;
cout<<" "<<endl;
}
}