Hi there!
This is my first post and I'm a complete noob to C, so
please bare with me.
I'm having an awful time trying to do true division.
All my variables are int type but my result comes out to 0.
I tried changing one of the variables to double but i'm getting compilation errors.
Here is the original code:
Code:
#include <stdio.h>
int main()
{
int resgallons;
int currentppm;
int targetppm;
int result
printf( "Enter a 2 digit number: How many gallons are in you res?\n" );
scanf("%d", &resgallons);
printf("Enter you current PPM level.\n");
scanf("%d", ¤tppm);
printf("Now enter your desired PPM level\n");
scanf("%d", &targetppm);
result = ( targetppm - currentppm) / targetppm * 8 * resgallons);
printf("%d", result);
return 0;
}
Then I tried this:
Code:
#include <stdio.h>
int main()
{
int resgallons;
int currentppm;
int targetppm;
int result
printf( "Enter a 2 digit number: How many gallons are in you res?\n" );
scanf("%d", &resgallons);
printf("Enter you current PPM level.\n");
scanf("%d", ¤tppm);
printf("Now enter your desired PPM level\n");
scanf("%d", &targetppm);
double result = ( (double)targetppm - currentppm) / targetppm * 8 * resgallons);
printf("%lf", result);
return 0;
}
But this gave me compilation errors.
Could someone point me in the right direction.