#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int main ()
{
    float nep,b,sum,temp,i,j,median;
    cout<<"Enter the number of Elements";
    cin>>nep;
    double element [10];
    int index;
    for (index=0;index<nep;index++)
    {
        element[index]=0.0;
    
        }
        for (index=0;index<nep;index++)
        {
            cin>>element[1];
            sum=element[1]+element[2];
            element[1]=element[2];
            element[2]=sum;	
         
            }
            b=sum/nep;
            cout<<"Mean:"<<b<<endl;
for(i=0;i<nep;i++)
for(j=i+1;j<nep;j++)
{
if (element[3]>element[4])
{
temp=element[4];
element[3]=element[4];
element[4]=temp;
}
}
if(nep/2==0)
{
median=(element[nep/2]+element[nep/2-1])/2;
cout<<"Median:"<<median<<endl;
}

            getche ();
            return 0;
            }

Good Day!

I'm a beginner in c++ programming that's why i'm having trouble. I'm using dev c++ as my case tool to write programs and when i tried using some sort of functions; it always making some error report. Please do help me. Can anyone edit my code using such functions so that dev c++ can read it. [i'm nor smart] Please help me. Thanks

-MhuR-

Recommended Answers

All 2 Replies

I can't read this code. The indentation is all messed up. You should format it. You should also stick some brackets in to make it crystal clear what's inside the for-loop starting on line 27.

>> it always making some error report.

What's the error message? You should provide it. Here I am guessing it doesn't like conio.h. To hold the execution window open, replace line 43 with

cin.get();

If that doesn't do the trick, add another

cin.get();

below it.

Delete line 3. You can probably delete line 2 as well, though it's harmless even if it doesn't do anything.

Line 39 you should type cast:

median = (element[(int)(nep/2)] + element[(int)(nep/2-1)]) / 2;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.