-
Issues with if statement
I am having issues with my if statement and have done everything I can think of to get it to work but it continues to return the first option no matter what I enter. Could someone please help...
if (prft1 >= 0)
{ if (prft1 == 0) printf("You have broken even from selling goldfish. \n", prft1 );
else
printf("Your profit from selling goldfish is $%.2f. \n", prft1);
}
else
printf("Your loss from selling goldfish is $%.2f. \n", prft1);
-
You might try it like this:
PHP Code:
[CODE]
if(prft1==0)
printf("You have broken even from selling goldfish. \n", prft1 );
else if(prft1>0)
printf("Your profit from selling goldfish is $%.2f. \n", prft1);
else
printf("Your loss from selling goldfish is $%.2f. \n", prft1);
[/CODE]
-
[ code ] tags please...
Have a look at this test version of your code:
Code:
#include <stdio.h>
void tester (float prft1);
int main(void)
{
float a, b;
tester (0.0);
tester (1.0);
tester (-1.0);
tester (1.1 - 1.1);
a = 1.1;
b = 2.2;
tester (a + b - 3.3);
return(0);
}
void tester (float prft1)
{
if (prft1 >= 0)
{
if (prft1 == 0)
{
printf("You have broken even from selling goldfish. \n", prft1);
}
else
{
printf("Your profit from selling goldfish is $%.2f. \n", prft1);
}
}
else
{
printf("Your loss from selling goldfish is $%.2f. \n", prft1);
}
}
/*
Output:
You have broken even from selling goldfish.
Your profit from selling goldfish is $1.00.
Your loss from selling goldfish is $-1.00.
You have broken even from selling goldfish.
Your profit from selling goldfish is $0.00.
*/
[edit]
And yes, a better formatting for the conditional statement would be good (as shown)
-
I have
I have tried both of those and still the same.. The second one that is posted gave me alot of errors... I am abt to pull my hair out...
-
Post more of your code, together with sample input+output, and any error messages you are getting for it.
-
How??
could you tell me how to post it.. I am using a unix system from UCF. :confused:
-
-
Code:
printf("You have broken even from selling goldfish. \n", prft1);
Why are you passing prft1 to printf? It will work because of _cdecl, but it's a wrong way to call printf