To Proskyslayer:
Ah , very good...your code should work :)
take note : calloc
(amount of this variables, sizeof(variable)) returns (pointer with
no type a.k.a void)*
remember to use sizeof (variable) to
measure the amount of memory space needed to store the variable
properly.
For debugging...
1. when you compile, look at the error code (if there is) and
try to understand what it is telling you...
2. if the output is not what you expect...insert printf
statement to list your variables. and try to work it out step by
step...
optimise solution...
you can download the file from here
http://www.4shared.com/file/qJHtrGQ5/testing.html
#include <stdlib.h>
{
float *Numbers=NULL ; // defines a pointer which will point to
an array later
int InputBuffer, I;
/* ask user for the amount of number to operate on */
do
{
printf("Please Enter How Many Number You Want to subtract(1 to
80): ");
scanf(" %d", &InputBuffer);
} while( ( InputBuffer < 1 ) || ( InputBuffer > 80 )
);
/* allocate actual memory space as an array base on user input
and have the pointer points to it */
Numbers = ((float*)calloc(InputBuffer+1, sizeof(float))); //
stores the amount from user plus 1 more for operative
if( Numbers == NULL )
{
printf( "You have not enough RAM and I don't care...bye bye :p "
); // just my random text...
system("pause");
return 1;
}
/* Ask user for numbers to be operated */
for( I = 0; I < InputBuffer; I++ )
{
printf( "Enter number %d: ", I+1 );
scanf(" %f", &Numbers[I]); // store all input to the front
of the array
}
/* The operative process */
Numbers[InputBuffer+1]=Numbers[0]; // load first number to the
end of initialised array and operate from there
for( I = 1; I < InputBuffer; I++ )
Numbers[InputBuffer+1] -= Numbers[I];
/* Presentation of the equations */
printf(" %g" , Numbers[0]); // display first number in the
equation
for( I = 1; I < InputBuffer; I++ ) // display subseqence
numbers in the equation
{
if (Numbers[I]<0)
printf( "-(%g)", Numbers[I] ); // better presentation of minus
by a negative number
else
printf( "-%g", Numbers[I] );
}
printf( "=%g ", Numbers[InputBuffer+1] ); // display final
result in the equation
system("pause");
return 0;
}