I have a question about how I can take a negative number to exit the loop without passing it to the sortarray function. I was going to use a sentinel but I'm stumped and need some suggestions.
#include <iostream.h>
#include <iomanip.h>
void sortarray(int [], int);
void main(void)
{
int count,k,tscores = 0;
int test[100];
for(count=0;count <100 ;count++)
{
cout << "\nEnter a number:";
cin >> test[count];
if(test[count]<0)
{
test[count-1];
break;
}
}
sortarray(test,count);
for(k=0;k<count;k++)
{
cout << test[count] <<endl;
}
}
void sortarray(int nums[],int count)
{
int hold,a,b;
for(a=0;a<count-1; a++)
{
for(b=a+1; b<count; b++)
{
if(nums[a]<nums[b])
{
hold = nums[a];
nums[a] = nums[b];
nums[b] = hold;
}
}
}
}