### template

I need to divide the random number by 10,000 when it runs as doublearray. Can someone point me in the right direction?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````#include #include //#include #include #include //#include const int N=1000; using namespace std; template void Bubble(type &ta) { //ofstream outfile("TriBubble.txt"); //{ for(int a=0; ata[c+1]) { swap(ta[c],ta[c+1]); } } } for(int e=0; e
Last edited on
I'm afraid you've confused me. I don't understand what you want.

What do you mean by "random number"? What random number? Why do you have to divide it by 10,000?

Also, your bubble sort function is doing waaay too many things. All it should do is sort your array, nothing else. No file I/O, no random initializations, no printing, nothing -- just sorting. Make other functions for those things.

Also, you should declare the function as:

 ``12345`` ``````template void Bubble(T (&ta)[ N ] ) { // sorts ta[] here... }``````

That way, you can call it with any array:

 ``12345678910`` `````` int intarray[] = { 7, 2, 3, 9, 5, 8, 1, 4, 6 }; double doublearray[ 500 ]; random_fill(doublearray); // you would need to write this function Bubble(intarray); Bubble(doublearray); print(cout,intarray); // you would need to write this function also print(cout,doublearray);``````

Hope this helps.
I wanted to know how I could have "rand()%N" divide by 10,000 because all of the doublearray values have to be divided by 10,000
I still don't know what you are getting at. Why can't you just divide them by 10000?
If I put in divide by 10000 it will do that for all of my other Bubbles and I only want it to divide when type is double. Do you know the if statement that I could use to tell it to divide by 10000 when type is a double?
No. Stop trying to do too many things at once.

Your main function should look something like this:

 ``1234567891011121314`` `````` int intarray[N]; char chararray[N]; double doublearray[N]; srand( (unsigned)time( 0 ) ); random_fill(intarray); random_fill(chararray); random_fill(doublearray); for (size_t n = 0; n < N; n++) doublearray[n] /= 10000; Bubble(intarray); etc``````

Every function should do one thing.

Good luck!
Thank you!
Topic archived. No new replies allowed.