🔒 Closed Pa help po int ang nalabas sa halip na float

Status
Not open for further replies.

Aroma

Honorary Poster
Andun po sa may median ang problem ko, int po kase nalabas pag ni rurun ko naka float naman siya.




#include <iostream>
using namespace std;



int main() {
int n;
cout << "Enter the Number of Observations" << endl;
cin >> n;
int numofobservations [n];


for (int x=0; x < n; x++){
cin >> numofobservations[x];

}

//Sorting Numbers
for (int x=0; x < n; x++ ){

for (int y = x+1; y < n+1; y++ ){
int store;

if (numofobservations[x] > numofobservations[y]){
store = numofobservations[x];
numofobservations[x] = numofobservations[y];
numofobservations[y] = store;
}
}
}
for (int x=0; x < n; x++){
cout <<" " << numofobservations[x] << " ";
}

//Mean Function
int meansum = 0;

for (int x=0; x < n; x++){

meansum+=numofobservations[x];

}
double mean = meansum / n;
cout << endl <<"Mean is :" << " " << mean << endl;

//Median
if (n % 2 == 0){

int test;

int stmedian = n / 2;
test = numofobservations[stmedian-1] + numofobservations[stmedian];
float median = test / 2;

cout<< "The median is:" << " " << median << endl;

}




return 0;
}
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 524
    Views
  • 4
    Participants
Last reply from:
N O B I T A

Trending Topics

Online now

Members online
1,337
Guests online
3,481
Total visitors
4,818

Forum statistics

Threads
2,305,879
Posts
29,168,309
Members
1,195,477
Latest member
Jomar Gabriel
Back
Top