472,374 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

Finding Median

i dont know wat is wrong with my code. when i compile. i get the error

saying line 29: error: expression must have pointer-to-object type


#include <iostream>
using namespace std;
#include <vector>

double* median(double a[], int a_size) // Function Median
{ // Start of Function ( Median )
double* median;
int i,j;
double temp;
int numbers; // Variable Declared Median
if (a_size == 0) // Start of If Statement
return NULL; // if the size of the array is zero the pointer returns NULL


for (i = a_size-1; i >= 0; i--) //sorts out the array in an ascending order
{ // Start of For Loop
for (j = 1; j <= i; j++) // For Loop
{
if (a[j-1] > a[j]) // If Statement to Check the VAlue of A
{ // Start of IF Statement
temp = a[j-1]; // Assign Temp value to a
a[j-1] = a[j]; // Array in Descending Order
a[j] = temp; // Assign array to Temp
} // close of IF Statement
} // Close of For Loop
} // close of For in For Loop
//if the size is even number than takes the average else returns the middle number
if (a_size % 2 == 0) //compares the size for even number
median = ((numbers[a_size/2]) + (numbers[(a_size+1)/2])/2);// Define Median
else // else odd size
median = numbers[a_size+1]; // Assgin median for Odd Number of Array

return median; // Return Median value to Main
} // Close of Function ( Median )

int main() // Function main
{

int first;
int num2;
int i; // Variable Declared ( int )
int Exit; // Variable Declared ( Dummy )

cout << "Enter The Length of First vector"; // Output Statement for the Length of 1st Vector
cin >> first; // User Input for the Length of 1st Vector
cout<<endl; // Blank Line
vector <int> a(first); // Vector First


for (i=0; i<first; i++) // Start of For Loop for User Input 1st Vector
{
cout<< "Please enter element "<<i+1<<" of the First Vector";// Output For Entering Vector
cin>>num2; // User Input
cout<<endl; // Blank Line
a[i] = num2; // Adding Element in Vector A
}


cout <<"The Median of the Data is :" << median*(a, first) << "\n"; //Displays the Medianimum value out of the array
cout<<" Please Enter Any Key to Exit";
cin>>Exit;
return 0;
}
Mar 27 '08 #1
3 4977
Sick0Fant
121 100+
You have a thing or two to learn about pointer aritmetic. The ar[x] always returns a value, not an address (unless it's an array of addresses, which I doubt numbers is). You should try (ar + x)
Mar 27 '08 #2
if i try ( ar + x ) the line gives me the error of

expression must have (pointer-to-) function type
:S

i also need some help in callin the function Median.. when it says..
cout <<"The Median of the Data is :" << median*(a, first) << "\n";
the error associated with this cout statement is

error: expression must have arithmetic or enum type
Mar 27 '08 #3
thankyou for you help :).
Mar 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Hugo L. | last post by:
I really don't know how to calculate the median. Can anybody help me?
2
by: Bob | last post by:
I have been looking at the code for MedianFind(pDte As String) from the following thread from UtterAccess.com: "Finding Median average grouped by field" I have been able to get it to run using...
4
by: uspensky | last post by:
I have a table (cars) with 3 fields: VIN, Class, sell_price 101, sports, 10000 102, sports, 11000 103, luxury, 9000 104, sports, 11000 105, sports, 11000 106, luxury, 5000 107, sports, 11000
12
by: erikcw | last post by:
Hi all, I have a collection of ordered numerical data in a list. The numbers when plotted on a line chart make a low-high-low-high-high-low (random) pattern. I need an algorithm to extract the...
3
by: Scott | last post by:
I need to take the median from a field of records in a report. Can someone shed the light how to do it. Thanks, Scott
3
by: Storm9 | last post by:
I have to: "Use functional decomposition to write a C++ program that determines the median of five input numbers. The median is the middle number when the five are arranged in order. However, the...
7
by: Bhadan | last post by:
Hello, I have several jagged arrays which have been sorted. I'm trying to find the median of each array. Any tips appreciated. TIA. Bhads.
2
by: curien | last post by:
Hello, I am working on a code that takes the users input ( a string of digits) from the command line and prints out the median number. I am trying to accomplish this by: from sys import argv ...
3
by: tkpmep | last post by:
I have coded a robust (Theil-Sen) regression routine which takes as inputs two lists of numbers, x and y, and returns a robust estimate of the slope and intercept of the best robust straight line...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.