if (x != 0)
{
cout << AllocateSpace[i] - x << endl;
}
Basically it says. if x is not equal to 0, then print out the numbered stored in AllocateSpace[i] and then subract x, which is the smallest number. So if for example, AllocateSpace[3] = 10.
And the smallest number = 3. Then 10 - 3 will give you 7.
If you are using x, you really don't need the "smallest" variable. It is declared, defined, but never used.
If the user actually enters 0 as the first integer and then only positive integers the differences will never print out.
On line 28 I'm almost certain you don't want to use AllocateSpace[x] as x is an actual integer entered by the user and not an index value.
Also if you want to display the differences between the numbers entered and the smallest number you need to do that after you have obtained the smallest number.
int main()
{
int num, smallest = 0, x;
cout << "How many integers do you want to enter?: ";
cin >> num;
int* AllocateSpace = newint[num];
cout << "Enter " << num << " numbers: " << endl;
for (int i = 0; i < num; ++i)
{
cout << "Enter number: ";
cin >> AllocateSpace[i];
}
x = AllocateSpace[0];
cout << "The differences between the numbers entered and the smallest number are: " << endl;
for (int i = 1; i < num; ++i) {
if (AllocateSpace[i] < x) { x = AllocateSpace[i]; }
if (x != 0)
{
cout << AllocateSpace[i] - x << endl;
}
}
cout << "Smallest number is: " << x << endl;
delete[] AllocateSpace;
system("pause");
return 0;
}