hey guys,
Im doing an assignment for tech... the tutor is somewhat useless
I need to make an array that can loop 10 random numbers and then display them, pass that to a function and then have that display all the numbers in ascending order using for, while and if condititional statements...
I've got the first part its the last bit Im having a bit of a fuss with...
heres my code:
#include <iostream>
#include <conio>
#include<stdio.h>
#pragma hdrstop
# include<cstdlib>
void printAsc(int[]);
using namespace std;
//---------------------------------------------------------------------------
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
srand( time(0) );
int randmNum[10];
int i = 0;
for (i = 0; i < 10; i++)
{
randmNum[i] = rand()%100+1;
cout << "Random Number " << i+1 << ": "
<< " - " << randmNum[i] << endl;
}
getch();
clrscr();
printAsc(randmNum);
getch();
return 0;
}
//---------------------------------------------------------------------------
void printAsc(int randNum[10])
{
int smallest;
int previousSmallest;
int previousLargest;
int largest;
smallest = randNum[0];
largest = randNum[0];
previousSmallest <= smallest;
smallest <= largest;
for (int i = 0; i < 10; i++)
{
if ( ( randNum[i] <= smallest ) )
{
previousSmallest = smallest;
smallest = randNum[i];
cout << smallest << endl;
}
if (randNum[i] >= largest)
{
previousLargest = largest;
largest = randNum[i];
cout << largest << endl;
}
}
getch();
}
I just chucked this together in like 20 mins earlier today... hope its pretty readable