i don’t know if some body asked this question before or not, but here is mine:
if i have following code; what the value of total will be?
Because the output is always in +ve value not the -ve, or please guide me where i am wrong.Thankyou.
P.S: Iam using Turbo C 3.o compiler.
void subtract (void)
{
float f1;
float f2=0.0;
float f3=0.0;
float total;
printf("Enter numbers to be subtract:'q' to quit.\n ");
while (scanf("%f",&f1)==1)
{
f3=f1+f2;
total=f3-f1;
printf("Enter another # to be subtract:'q' to quit.\n ");
scanf("%1.0f",&f1);
}
printf("Subtraction Total = %1.0f",total);
getch();
}
//I am using now for simple subtraction like 3.6-9.2, i am not getting -5.6 instead I am getting 9 (This for Example)
I done it what i just want by do the following; Thank you all
void subtract (void)
{
float f1;
float f2;
int status1,status2;
float total;
printf("Enter first number to subtract:'n' to quit.\n ");
status1=scanf("%f",&f1);
printf("Enter second number to be subtract from first:'n' to quit.\n ");
status2=scanf("%f",&f2);
while (status1==1 && status2==1)
{
total = f1 - f2;
printf("total=%1.2f \n",total);
printf("Enter first number to subtract:'n' to quit.\n ");
status1=scanf("%f",&f1);
printf("Enter second number to be subtract from first:'q' to quit.\n ");
status2=scanf("%f",&f2);
}
printf("Subtraction Total = %1.1f",total);
getch();
}
I done it what i just want by do the following; Thank you all
void subtract (void)
{
float f1;
float f2;
int status1,status2;
float total;