I have been working on this problem so much, I have started to think in Binary.
what I am supposed to do is put User defined numbers in acending order.
Here is what I tried.
(please dont laugh)

#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

void testSort(int [], int);
void testShow(int [], int);

int main()
{
     int count=0;
     int testNum=0;
     const int SIZE=50;
     vector<int> test(SIZE);
     int Avg1=0;
     double Avg2=0;
     
     cout <<"how many tests will you be entering? ";
     cin >> testNum;
     
     for (count=0; count < testNum; count++)
     {
      cout << "enter score for test "<< count+1<<" : ";
      cin >> test[count];
      Avg1+=test[count];
     }
     Avg2=static_cast<int> (Avg1)/testNum;
     
     testSort(test, SIZE);
     
//this is to show the grades in acending order

     for (int count = 0; count < testNum; count
         {
          cout<< test[count] << endl;
         }
     
     cout << "your average score is: " << Avg2<<endl;
      
     
     system("pause");
     return 0;
}

void testSort(int test[], int SIZE)
{
     int startScan, minIndex, minValue;
     
     for (startScan = 0;startScan < (SIZE-1); startScan++)
     {
         minIndex = startScan;
         minValue = test[startScan];
         for(int count = startScan +1; count <SIZE; count++)
         {
          if (test[count]<minValue)
             {
                  minValue = test[count];
                  minIndex = count;
             }
          }
          test[minIndex] = test[startScan];
          test[startScan] = minValue;
     }
}

if this looks rediculous, it is because I have tried everything I can think of.
Please help, thank you for your time

Recommended Answers

All 10 Replies

Here is how I code that function.

void testSort(int test[], int SIZE)
{
    for (startScan = 0;startScan < (SIZE-1); startScan++)
    {
         for(int count = startScan +1; count <SIZE; count++)
         {
              if (test[startScan] < test[count])
             {
                  int temp = test[startScan];
                  test[startScan] = test[count];
                  test[count] = temp;
             }
          }
     }
}

I tried that and got this error message
cannot convert `std::vector<int, std::allocator<int> >' to `int*' for argument `1' to `void testSort(int*, int)'

You get that error because you are passing a vector and the function wants an int array. Not the same thing. So just change the function to this:

Note, this doesn't need the second parameter SIZE because vectors know their size.

void testSort(vector<int>& test)
{
    for (int startScan = 0;startScan < (test.size()-1); startScan++)
    {
         for(int count = startScan +1; count < test.size(); count++)
         {
              if (test[startScan] < test[count])
             {
                  int temp = test[startScan];
                  test[startScan] = test[count];
                  test[count] = temp;
             }
          }
     }
}

what exactly is "ubt?" I can't find it in my book.

what exactly is "ubt?" I can't find it in my book.

I have no idea either. Where did you see that ?

here
void testSort(vector<int>& test)
{
for (ubt startScan = 0;startScan < (test.size()-1); startScan++)
}

It is my mispelling of int. I hit the wrong keys and didn't notice it.

ah, that makes sense

it still is not working, so I was thinking, might the atoi finction work to solve this?

worked for me. delete all references to SIZE and call resize() after you know how many elements are to be entered.

how many tests will you be entering? 5
enter score for test 1 : 5
enter score for test 2 : 3
enter score for test 3 : 1
enter score for test 4 : 2
enter score for test 5 : 4
5
4
3
2
1
your average score is: 3
Press any key to continue . . .
int main()
{
     int count=0;
     int testNum=0;
     vector<int> test;
     int Avg1=0;
     double Avg2=0;
     
     cout <<"how many tests will you be entering? ";
     cin >> testNum;
     test.resize(testNum);
     for (count=0; count < testNum; count++)
     {
      cout << "enter score for test "<< count+1<<" : ";
      cin >> test[count];
      Avg1+=test[count];
     }
     Avg2=static_cast<int> (Avg1)/testNum;
     
     testSort(test);
     
//this is to show the grades in acending order

     for (int count = 0; count < testNum; count++)
     {
          cout<< test[count] << "\n";
     }
     
     cout << "your average score is: " << Avg2<<endl;
      
     
     system("pause");
     return 0;
}

void testSort(vector<int>& test)
{
     
     for (unsigned int startScan = 0;startScan < (test.size()-1); startScan++)
     {
         for(unsigned int count = startScan +1; count < test.size(); count++)
         {
          if (test[startScan] > test[count] )
             {
                 int temp = test[startScan];
                 test[startScan] = test[count];
                 test[count] = temp;
             }
          }
     }
}

Thank you Ancient, your programming knowlege has saved yet annother hide.
the Bunny below thanks you too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.