#include
<stdio.h>
#include
<stdlib.h>
int
main(void
)
float
*Numbers = NULL,J[80], BiggestNum = 0,Total = 0, Q;
int
InputBuffer = 0;
int
I = 0 , Total1=0;
do
{
printf(
"Please Enter How Many Number You Want to subtract(1~80): "
);
"%d"
, &InputBuffer );
while
( ( InputBuffer < 1 ) || ( InputBuffer > 80 ) );
float * )calloc( InputBuffer, sizeof( int
) ) );
if
( Numbers == NULL )
"Failed to allocate the array. Exiting"
);
return
1;
"Enter Number[1]: "
);
"%f"
,&J[80]);
for
( I = 0; I < InputBuffer; I++ )
"Enter number[%d]: "
, ( I + 2 ) );
"%f"
, &BiggestNum );
for
( I = 0; I < InputBuffer ; I++ )
if
( BiggestNum < Numbers[I] )
for
( I = 0; I < InputBuffer; I++ )
" Subtract of the numbers entered is: %f "
, Total );
return
0;
[could not subtract pls help]
did you check what you post? missing instructions and wrong syntax make this hard to even interprete what you are trying to do...
Originally posted by Proskyslayer:
#include
<stdio.h>
#include
<stdlib.h>
int
main(void
)
float
*Numbers = NULL,J[80], BiggestNum = 0,Total = 0, Q;
int
InputBuffer = 0;
int
I = 0 , Total1=0;
do
{
printf(
"Please Enter How Many Number You Want to subtract(1~80): "
);
"%d"
, &InputBuffer );
while
( ( InputBuffer < 1 ) || ( InputBuffer > 80 ) );
float * )calloc( InputBuffer, sizeof( int
) ) );
if
( Numbers == NULL )
"Failed to allocate the array. Exiting"
);
return
1;
"Enter Number[1]: "
);
"%f"
,&J[80]);
for
( I = 0; I < InputBuffer; I++ )
"Enter number[%d]: "
, ( I + 2 ) );
"%f"
, &BiggestNum );
for
( I = 0; I < InputBuffer ; I++ )
if
( BiggestNum < Numbers[I] )
for
( I = 0; I < InputBuffer; I++ )
" Subtract of the numbers entered is: %f "
, Total );
return
0;
[could not subtract pls help]
i suggest threadstarter to copy and paste whole source code into notepad ,save as text file ,reopen and paste the whole text here , otherwise i will have feel threadstarter didnt initialise the variable ..
thanks
Originally posted by Twincat:did you check what you post? missing instructions and wrong syntax make this hard to even interprete what you are trying to do...
I suppose the WYSIWYG editor for the post displays differently from the post after it is osted.
Originally posted by joeyfjj:I suppose the WYSIWYG editor for the post displays differently from the post after it is osted.
yes naturally, thats why always check your post after sumit...
poor TS, having difficulties and like nobody helping...
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float *Numbers = NULL,J[80], BiggestNum = 0,Total = 0,Q;
int InputBuffer = 0;
int I = 0 , Total1=0;
do
{
printf( "Please Enter How Many Number You Want to subtract(1~80): " );
scanf( "%d", &InputBuffer );
InputBuffer = InputBuffer-1;
} while( ( InputBuffer < 1 ) || ( InputBuffer > 80 ) );
Numbers = ( ( float * )calloc( InputBuffer, sizeof( int ) ) );
if( Numbers == NULL )
{
printf( "Failed to allocate the array. Exiting" );
getchar( );
return 1;
}
{
printf("Enter Number[1]: ");
scanf("%f",&Q);
J[80] = Q ;
}
{
for( I = 0; I < InputBuffer; I++ )
{
printf( "Enter number[%d]: ", ( I + 2 ) );
scanf( "%f", &BiggestNum );
Numbers[I] = BiggestNum;
}
BiggestNum = 0;
for( I = 0; I < InputBuffer ; I++ )
if( BiggestNum < Numbers[I] )
BiggestNum = Numbers[I];
for( I = 0; I < InputBuffer; I++ )
Total = J[1] -= Numbers[I];
printf( "
Sum of the numbers entered is: %f
", Total );
return 0;
}
}
The OutPut Of This program should be something like this
How many numbers do you want to subtract: 3
Please enter number 1: 12
Please enter number 2: 2.5
Please enter number 3: 0.25
12 - 2.5 - 0.25 = 9.25
so do you actually intend to use the BiggestNum var to look for the largest value and put as the 1st number to be substructed?
Anyway the raw solution...if any question feel free to ask...
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float *Numbers = NULL, BiggestNum = 0,Total;
int InputBuffer, I;
do
{
printf("Please Enter How Many Number You Want to subtract(1~80): ");
scanf(" %d", &InputBuffer);
} while( ( InputBuffer < 1 ) || ( InputBuffer > 80 ) );
Numbers = ( ( float * )calloc( InputBuffer, sizeof( float ) ) );
if( Numbers == NULL )
{
printf( "Failed to allocate the array. Exiting " );
system("pause");
return 1;
}
for( I = 0; I < InputBuffer; I++ )
{
printf( "Enter number[%d]: ", I+1 );
scanf( "%f", &Numbers[I] );
}
Total=Numbers[0];
for( I = 1; I < InputBuffer; I++ )
Total -= Numbers[I];
printf( " Sum of the numbers entered is: %g ", Total );
getchar();
system("pause");
return 0;
}
er.. i wish to use J[80] to mins the total Number[I].
I can't figure what is your requirement....
Does J[80] = number 2 + number 3 ... + number N
so total = number 1 - J[1 to 80] ?
what do you want with Numbers[I] then?
can you list your assigment question instead?
You really should give us more info if you really need help....
You can also do psedo code....
Lets say i need 1 to 80 float number input from user... (stating your requirements)
then i store each input into array var Numbers... (list your var purpose)
using Total = Numbers [0] - Numbers [1 to Inputbuffer]... (list your operation)
Please take note...
lets say
float arrayf[80];
int fail;
arrayf is an 80 box container that contain floats , first box is arrayf[0] and last box is arrayf[79]
if you try to assign ...
arrayf[80] = 1;
you are going to corrupt any var that is declared after arrayf, or strictly speaking, the memory space after arrayf.
How many numbers do you want to subtract: 3
Please enter number 1: 12
Please enter number 2: 2.5
Please enter number 3: 0.25
12 - 2.5 - 0.25 = 9.25
[This is the wanted Output]
[J[80] is the 1st number in this case is 12]
Number1[I] is the array store like number 2 n 3
There for the Calculation i guess will be J[80]-Number1[I]
(2) Subtraction
Mini-Project
Page 2 of 3
The program will prompt the user for the amount of numbers to enter. Thereafter the program will prompt the user for the correct numbers to subtract, and display the result.[DO WITH ARRAY] How many numbers do you want to subtract: 3 Please enter number 1: 12 Please enter number 2: 2.5 Please enter number 3: 0.25 12 - 2.5 - 0.25 = 9.25
|
The program will prompt the user for the amount of numbers to enter. Thereafter the program will prompt the user for the correct numbers to subtract, and display the result. How many numbers do you want to subtract: 3 Please enter number 1: 12 Please enter number 2: 2.5 Please enter number 3: 0.25 12 - 2.5 - 0.25 = 9.25
|
Raw solution... you should be able to make the necessary changes...it is a simple question. If you could operate just from 1 array is even better.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float *Numbers = NULL, BiggestNum = 0,Total, J[81];
int InputBuffer, I;
do
{
printf("Please Enter How Many Number You Want to subtract(1~80): ");
scanf(" %d", &InputBuffer);
} while( ( InputBuffer < 1 ) || ( InputBuffer > 80 ) );
Numbers = ( ( float * )calloc( InputBuffer, sizeof( float ) ) );
if( Numbers == NULL )
{
printf( "Failed to allocate the array. Exiting" );
system("pause");
return 1;
}
printf( "Enter number 1: ");
scanf( " %f", &J[80] );
printf( " ");
for( I = 0; I < InputBuffer-1; I++ )
{
printf( "Enter number %d: ", I+2 );
scanf( "%f", &Numbers[I] );
}
Total=J[80];
for( I = 0; I < InputBuffer; I++ )
Total -= Numbers[I];
printf( " Sum of the numbers entered is: %g ", Total );
getchar();
system("pause");
return 0;
}
wow i didnt think of THAT THANKS!!
er.. just a slight question how about divide ?
i change the Total-=Numbers[I]
to
Total / = Numbers[I]
& it didnt work is there anything i done wrong?
The OutPut Of The Programming should be
How many numbers do you want to divide: 3 Please enter number 1: 12 Please enter number 2: 4 Please enter number 3: 2 12 / 4 / 2= 1.5
|
so what did you get? Hope there is no spacing between / and =....
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float *Numbers = NULL, BiggestNum = 0,Total, J[81];
int InputBuffer, I;
do
{
printf("Please Enter How Many Number You Want to subtract(1~80): ");
scanf(" %d", &InputBuffer);
} while( ( InputBuffer < 1 ) || ( InputBuffer > 80 ) );
Numbers = ( ( float * )calloc( InputBuffer, sizeof( float ) ) );
if( Numbers == NULL )
{
printf( "Failed to allocate the array. Exiting" );
system("pause");
return 1;
}
printf( "Enter number 1: ");
scanf( " %f", &J[80] );
printf( " ");
for( I = 0; I < InputBuffer-1; I++ )
{
printf( "Enter number %d: ", I+2 );
scanf( "%f", &Numbers[I] );
}
Total=J[80];
for( I = 0; I < InputBuffer; I++ )
Total /= Numbers[I];
printf( " Sum of the numbers entered is: %g ", Total );
getchar();
system("pause");
return 0;
}
[It did not work , i gt 1#INF]
>.<
aft dividing 81/9/3 >.<
So in what situation will you get a solution with 1#inf ?
give you a clue where the logical fault might be :
Total=J[80];
for( I = 0; I < InputBuffer; I++ ) <- how many times do you think it have run?
Total /= Numbers[I];
you need to learn a few tricks in debuging...
Total=J[80];
for( I = 0; I < InputBuffer; I++ )
{
printf (" I = %d , Numbers[%d] =%f ",I,I, Numbers[I]); <--you could use this or use break point features to debug
Total /= Numbers[I];
}
hahas seriously idk where should i start to debug >.<
er.. every divide there is a error
how many times it will run? << basically between 1-80[letting the user to input]
i uses printf (" I = %d , Numbers[%d] =%f ",I,I, Numbers[I]); as in not good with break.
i tried but to no avail >.<
giv me some hints thanks :)
1.#inf means that there is something getting divide by zero....you know wht happen when numbers get divided by zero?
printf (" I = %d , Numbers[%d] =%f ",I,I, Numbers[I]);
the above statement does not solve anything but it is your 2nd clue...
it is trying to print to screen what you are dividing in the variables...
you should notice why there is Numbers[2] (on the last printout) in that loop and also feel odd about its value...
how many times it will run? << basically between 1-80[letting the user to input] <-- this is what you think...is that what you tell the pc to do?
ok i guess i know where is the problem
after the printf(" ");
The for -loop which have a inputBuffer of -1 should be remove
instead it should be put @ the top b4 the for -loop izzit correct to said it?
This is the new written programme pls take a look :)
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float *Numbers = NULL, BiggestNum = 0,Total, J[81];
int InputBuffer, I;
do
{
printf("Please Enter How Many Number You Want to subtract(1~80): ");
scanf(" %d", &InputBuffer);
} while( ( InputBuffer < 1 ) || ( InputBuffer > 80 ) );
Numbers = ( ( float * )calloc( InputBuffer, sizeof( float ) ) );
if( Numbers == NULL )
{
printf( "Failed to allocate the array. Exiting" );
system("pause");
return 1;
}
printf( "Enter number 1: ");
scanf( " %f", &J[80] );
printf( " ");
InputBuffer = InputBuffer -1;
for( I = 0; I < InputBuffer; I++ )
{
printf( "Enter number %d: ", I+2 );
scanf( "%f", &Numbers[I] );
}
Total=J[80];
for( I = 0; I < InputBuffer; I++ )
{
printf (" I = %d , Numbers[%d] =%f ",I,I, Numbers[I]);
Total /= Numbers[I];
}
printf( " Sum of the numbers entered is: %g ", Total );
getchar();
system("pause");
return 0;
}