NEWB alert, lol. This was homework that I failed because i didnt turn it in on time. I didnt turn it in due to the fact that i took an online course, my book sucks and my instructor only checks his e-mail once a wk. that and i couldnt for the life of me figure out why my search "for loop" in my printInt function wont return the proper count. everything compiles o.k. my loop looks exactly like the one in the book and the online lecture. If someone can point out my mistake so i can use it properly next time i would be very grateful.
my whole program:
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
void printInts ( int randomArray[], int size, int& extra )
{
int counter;
for ( counter = 0; counter <size-1; counter++ )
{
cout<<setw(30)<<" Random number "<<(counter + 1)<<" generated "<<randomArray[counter]<<endl;
}
cout << " \n ";
cout <<setw(40)<<" The extra random number is: "<< randomArray[20]<< "\n" <<endl;
extra+= randomArray[20];
int counter1 = 0;
for ( counter1 = 0; counter1 <randomArray[size-1]; counter1++ )
{
if ( randomArray[counter1] == extra )
{
(counter1++);
}
}
cout << setw(38) << " The extra number occured " << counter1 << " times " << endl;
}
void getRandom ( int randomArray[], int size )
{
int counter;
int raNum;
int rand_max = 10;
int rand_min = 1;
srand(static_cast<unsigned int>(time(0)));
for ( counter = 0; counter <size; counter++ )
{
raNum = (rand() % (rand_max - rand_min + 1)) + rand_min;
randomArray[counter] = raNum;
}
int main ()
{
const int size = 21;
int randomArray[size];
int extra;
system ("color 1f ");
cout << " \n\n ";
cout << setw(40 + ( 32 / 2 )) << " 20 Random #'s will be generated " <<endl;
cout << " \n ";
getRandom ( randomArray, size );
printInts ( randomArray, size, extra );
cout << " \n ";
system ("pause");
return 0;
}