Dynamically Allocated Array Issue

So, I need to be able to pass a parameter used by function addElement and add that element into a dynamically allocated array. But for some reason when I am trying to add the value into the array I cannot get it to display correctly. Obviously because I'm not adding it in correctly but was hoping yall could help. Here's my code for my header and implementation files.

Header File:
#ifndef NUMBERCOUNT_H
#define NUMBERCOUNT_H

class NumberCount
{
private:
int min;
int max;
int num;
int *count;

public:
NumberCount(int,int);
void addElement(int);
void display();

};

#endif

----------------------------------------------------------------------------

Implementation File:
#include <iostream>
#include <new>
#include "NumberCount.h"
using namespace std;

int main()
{
NumberCount N(11,16);
N.addElement(12); N.addElement(12); N.addElement(12); N.addElement(14);
N.display();
}

NumberCount::NumberCount(int minimum, int maximum)
{
min = minimum;
max = maximum;
count = new int[max-min+2];
}

void NumberCount::addElement(int number)
{
num = number;
int i = 0;

if((num >= min) && (num <= max))
{
count[i] = num;
i++;
}
}

void NumberCount::display()
{
cout << "Minimum and Maximum are: ";
cout << min << "," << max << endl;
cout << "The array contains: ";
for(int i = 0; i <= (max-min+1); i++)
{
cout << count[i] << endl;
}
}
In addElement you always write the value to index 0.
Peter87 yeah I ended up figuring almost everything out last night. I just had to create a private increment variable that would keep up with the location of which element in the array the function left off at last. Thanks though!!!
Topic archived. No new replies allowed.