Where a number in an array would fall

Hi guys,
I'm having a problem doing a homework assignment. I've got everything to work so far, but I'm stumped on part of it. I'm trying to have the program indicate where in the array a new number would be placed if added. Any help or a point in the right direction would be helpful. Here's what I have.

#include <iostream>

using namespace std;
void input (int ulist[26], int& n);
void BubblesortA (int ulist[26], int slist[26], int n);
void BubblesortB (int ulist[26], int slist[26], int n);
void print(int list[26], int n);
float val, mean, sum, median, variance, v;

int main()
{
int n;
int ulist[26], slist[26];

input(ulist, n);
cout << "Sorted ascending";

BubblesortA (ulist,slist, n);
print(slist, n);

cout << "Sorted descending";
BubblesortB (ulist,slist,n);
print(slist,n);

cout << "Mean is "<< mean << "\n";
cout << "Median is "<< median << "\n";
cout << "Variance is = " << variance;
cout << "\n\n";
cout << "Enter antoher number: ";
cin >> v;

{
if (v < mean)
cout << v << " is less than the Mean";
if (v > mean)
cout << v << " is greater than Mean";
if (v == mean)
cout << v << " is equal to the Mean";
}

}
void input(int ulist[26], int& n)

{
cout << "Please enter 10 numbers \n";
int i(0);

while (i<10)
{
i++;
cin >> (ulist[i]);
}
n=i;
cout << "\n\n";
}


void BubblesortA(int unlist[26], int sortlist[26], int n)
{
int i,j,temp;
for (i=1;i<=n;i++)
sortlist[i] = unlist [i];
for (j=1;j<=n-1;j++)
for (i=1;i<=n-j;i++)
if (sortlist[i] > sortlist[i+1])
{
temp = sortlist[i];
sortlist[i] = sortlist[i+1];
sortlist[i+1] = temp;
}

}
void BubblesortB(int unlist[26], int sortlist[26], int n)
{
int i,j,temp;
for (i=1;i<=n;i++)
sortlist[i] = unlist [i];
for (j=1;j<=n-1;j++)
for (i=1;i<=n-j;i++)
if (sortlist[i] < sortlist[i+1])
{
temp = sortlist[i];
sortlist[i] = sortlist[i+1];
sortlist[i+1] = temp;
}
}
void print(int list[26], int n)

{
int i;
sum = 0;
cout << " list of numbers are : \n";
for (i=1; i<=n; ++i)
{
cout << list[i] << '\n';
sum = sum + list[i];
}
mean = sum/n;
cout << "\n\n";


median = ((list[5]+list[6])/2);

{
for (int i = 1; i < n; i++)

{
sum += ((list[i] - mean) * (list[i] - mean));
}
variance = sum / (n-1);

}



Last edited on
Please put [code][/code] around your code. Your code is very hard to read at this point and has probably attributed to why no one has replied to your question yet.
Agree
Topic archived. No new replies allowed.