The slot determination is easy, below range, range, over range.
int counter[ 9 ];
i = counter[ n ] ; is the value so...
int *pCnt = &counter[ n ];
Gives you a pointer to the integer located at cell [n].
Or try this.
int *pCnt = counter;
while( n-- )
{
int i = *pCnt++;
}
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
First problem that array is empty (not initialized).
Second, you only want the value, not the address for printing!
// YOU need t fill counter
// and initialize n like in a loop reference or something.
//i = counter[ n ] ;
int *pCnt = &counter[ n ];
for (n=0; n < 9; n++)
{
counter[n] = n;
}
cout << " Range Number" << endl;
cout << "$200 - $299\t " << counter[ 0 ] << endl;
cout << "$300 - $399\t " << counter[ 1 ] << endl;
cout << "$400 - $499\t " << counter[ 2 ] << endl;
cout << "$500 - $599\t " << counter[ 3 ] << endl;
cout << "$600 - $699\t " << counter[ 4 ] << endl;
cout << "$700 - $799\t " << counter[ 5 ] << endl;
cout << "$800 - $899\t " << counter[ 6 ] << endl;
cout << "$900 - $999\t " << &counter[ 7 ] << endl;
cout << "Over $1000 \t " << counter[ 8 ] << endl;
}
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
void displayResults( );
change this to:
void displayResults(int *, int);
Change declaration of counter to this:
const int SIZE = 9;
int counter[SIZE];
call displayResults() like this:
dipsplayResults(counter, SIZE);
Try to define it on your own.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Sorry I think I confused you
void displayResults(int*pCnt, int , nCnt)
{
cout << " Range Number" << endl;
cout << "$200 - $299\t " << *(pCnt+0) << endl;
cout << "$300 - $399\t " << *(pCnt+1) << endl;
etc.
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
Sorry let's try that again.
void displayResults(int*pCnt, )
{
cout << " Range Number" << endl;
cout << "$200 - $299\t " << *(pCnt+0) << endl;
cout << "$300 - $399\t " << *(pCnt+1) << endl;
etc.
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
In this program it's probably easier to write out the display as opposed to using a loop so you could follow this outline:
void display(int *);
int main()
{
const int SIZE = 9;
int counter[SIZE] = {0};
//do dah
display(counter);
//finish up
}
void display(int * counter)
{
cout << " Range Number" << endl;
cout << "$200 - $299\t " << counter[0] << endl;
cout << "$300 - $399\t " << counter[1] << endl;
//etc
}
You want to pass counter as an argument to display(), not declare it in display().
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Okay. I had enough!
It had been 11 posts in this thread and I cannot belive no one told OP to use code tags.
To the OP, it doesn't mean you shouldn't be knowing about code-tags. You should be posting the code using code-tags. Information about code-tag is posted all over the website :
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
And so far nobody has told you that it's better to avoid using system("pause");
Use cin.get(); as a replacement of system("pause"); , less typing and more portable :) !!
Check out this if you want to know why :)
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243