i have this code here which inputs the numbers and then adds them. is there a cheats way i can change it so that it inputs the numbers then puts them into ascending order.

#include <iostream.h>
void getNumber(int &, int); 
void sum( int, int &); 
void output(int[ ], int, int); 
int main()
{
const int SIZE = 10;
int array[SIZE] = {0};
int total = 0;
for ( int i = 0; i < SIZE; i++)
{

getNumber(array[i], i + 1);
sum( array[i], total);
}

output(array, total, SIZE);
}void getNumber(int &num, int numCount)
{
cout << "Enter number " << numCount << ":";
cin >> num;
}
void sum(int num, int &total)
{
total += num;
}

void output(int array[ ], int total, int arraySize)
{
cout << "The sum of ";
for (int i = 0; i < arraySize; i++)
{
cout << array[i] ;

if( i < arraySize - 1)
cout << " + ";
}
cout << " is " << total << endl;
system ("pause");
}

Recommended Answers

All 2 Replies

Once your array is filled, it's not cheating to use a sort function.

Cheats?? :-O

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.