ah yes thanks! there is a second part that requires pointer arithmetic to calculate the mean and median, I've managed to do this but I'm unsure whether this is pointer arithmetic
That asterisk on Line 8 is a dereference operator so this isn't pointer arithmetic, this is arithmetic that happens to involve a pointer which when you get down to it is just straight math. You're doing just fine from what I can see. There isn't really a scenario where 'j' would need to be a signed integer, but that is really "grasping at straws"* and barely worth mentioning.
*: That was really only written a snarkey\passive-aggressive jab at someone here who is apparently unfamiliar with the term.
haha fair enough, last question:
Without using a linked list, or defining a large sized array, write a simple program which prompts the user to
enter in a set of positive numbers. There can be an arbitrary number of numbers in the set.
You can assume the numbers are of type integer. A user can stop entering numbers by using a sentinel such
as -1.
how would I go about doing that? I have:
1 2 3 4 5 6 7 8 9 10 11 12 13
int index = 0;
int input[index];
while(input[index] != -1) //input will continue till -1 is entered
{
cout << "Enter Integer Value: ";
cin >> input[index];
cout << input[index] << endl;
if(input[index] != -1)
{
index++;
}
}
but I've been informed that this is a bad idea... thoughts?
ah I thought someone would say vectors :) thanks but I'm not allowed to use them just yet :( but from what I understand so far they would solve all my problems :P
I thought that might be the case, but I was hoping this would be easy. :)
I think they want you to use dynamic allocation. That is, using the 'new' operator to dynamically allocate new memory as you need it. Line 2 in your current code is not valid, you cannot create an array with a variable, and even if it could it would have a size of zero in this case.