| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
median of even slotted array
I have this program that I need to write. here is what I have, I'm stuck with trying to find the median of array. There should be an option for whether or not the array has even or odd slots. Down at the bottom is what I have for this option, but am getting errors. Any suggestions?
#include <iostream> #include <iomanip> using namespace std; int main() { float temp, input, median; int inputcount=0,n, m; float ary[11] ; cout << "Enter values: do -1 to stop program" << endl; cin >> input; while(input != -1 && inputcount < 9) { inputcount++; ary[inputcount] = input; cin >> input; } for(int i=0; i < inputcount+1; i++) { for( int j=0; j<inputcount; j++) { if( ary[j] > ary[j+1]) { temp = ary[j]; ary[j] = ary[j+1]; ary[j+1] = temp; } } } cout << endl << "Array Values:" << endl; for(int x=1; x<inputcount+1; x++) { cout << ary[x] <<endl; } if(inputcount % 2 == 0){ inputcount/2 = n; ary[n] + ary[n+1] = temp; temp/2 = median; } else{ inputcount - 1 = n; n/2 = m; m + 1 = n; ary[n] = median; } cout << endl << "The median is:" << median; return 0; } |
|
#2
|
||||
|
||||
|
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 275
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > median of even slotted array |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|