GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Nov-2009, 15:00
Lil_blue_dude Lil_blue_dude is offline
New Member
 
Join Date: Sep 2009
Posts: 8
Lil_blue_dude is on a distinguished road

Using pointer notation


I'm suppose to create a function that finds the median in an array. I can assume that the array is sorted, so when I test my function I am entering my data in ascending order. In my main function it asks the user for how many numbers will be in the array, asks the user to input data, and then calls the calcMedian function. The calcMedian function then finds the median(the purpose of my assignment).
Here is my code:
CPP / C++ / C Code:
#include<iostream>
using namespace std;

void calcMedian(double [], int);

int main()
{
    int arraySize;
    cout << "Please enter how many numbers you are going to enter: ";
    cin >> arraySize;
    double numbers[arraySize];
    for(int j = 0; j < arraySize; j++)
    {
            cout << "Please enter a positive number: ";
            cin >> numbers[j];
    }
    calcMedian(numbers, arraySize);
    system("Pause");
}
void calcMedian(double array[], int size)
{
     int middle;
     double median;
     if ((size % 2) != 0)
     {
            middle = ((size - 1) / 2);
            median = array[middle];
     }
     else
     {
            middle = size / 2;
            median = ((array[middle] + array[middle - 1]) / 2);
     }
     cout << "The median is: " << median << endl;                         
}
Everything works fine, the median is found and displayed properly, but I do not understand where I can use pointer notation or how it works. I am so incredibly lost in this chapter and do not know where to begin. Any help would be much appreciated.
  #2  
Old 02-Nov-2009, 15:32
Lil_blue_dude Lil_blue_dude is offline
New Member
 
Join Date: Sep 2009
Posts: 8
Lil_blue_dude is on a distinguished road

Re: Using pointer notation


I figured it out
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Giving garbage value as the result of product winner C Programming Language 10 19-Jul-2008 02:47
About my Sorting with Pointer Notation Program.(Help)! cougar1112 C++ Forum 3 16-Nov-2005 07:46
Sorting program using pointer notation NEED HELP!! cougar1112 C++ Forum 16 14-Nov-2005 12:15
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 18:36

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:59.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.