473,915 Members | 4,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding Median

3 New Member
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 5173
Sick0Fant
121 New Member
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
mehwishobaid
3 New Member
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
mehwishobaid
3 New Member
thankyou for you help :).
Mar 27 '08 #4

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

Similar topics

2
9147
by: Hugo L. | last post by:
I really don't know how to calculate the median. Can anybody help me?
2
2532
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 Northwind no problem. I am having some trouble though converting it to my specific purpose which may be less complicated than the solution Bob (raskew) provided in the thread. Here are my specifics:
4
8185
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
1788
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 "significant" high and low points from this data. Here is some sample data: data =
3
4677
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
7037
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 user can input the values in any order, so your program must determine which value is between the other two. For example, if the user enters: 41.52 27.18 96.03 12.5 13.8 then the program would output: The median of 41.52, 27.18, 96.03, 12.5,...
7
36052
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
3502
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 nums = argv for index, value in enumerate(nums): nums = float(value)
3
1846
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 fit. In a pre-processing phase, I create two new lists, x1 and y1; x1 has only the unique values in x, and for each unique value in x1, y1 has the median of all such values in x. My code follows, and it seems a bit clumsy - is there a cleaner...
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11354
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5943
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4778
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.