B
Bill Cunningham
I need help on this utillity it is supposed to take as its first
argument a number and its second argument a subtraction of that number say
for example 20 and 2. The program should calculate the percentage lost or
gained by the first number using the second number. This program is
reporting to me the opposite of what it should and I have tried everything.
It says this.
20 2
or 2 from 20 leaving 18 is 90% loss.
2 from 20 is a 10% loss. What's wrong with the formula?
#include <stdio.h>
#include <stdlib.h>
#define ex exit(EXIT_FAILURE)
int main (int argc, char *argv[]) {
if (argc!=3) {
puts("beta usage error");
ex;
}
double x,y;
x=strtod(argv[1],NULL);
y=strtod(argv[2],NULL);
double percent(double a,double b) {
double per;
per=(a-b)*100/a;
return per;
}
printf("%.2f",percent(x,y));
return 0;
}
argument a number and its second argument a subtraction of that number say
for example 20 and 2. The program should calculate the percentage lost or
gained by the first number using the second number. This program is
reporting to me the opposite of what it should and I have tried everything.
It says this.
20 2
or 2 from 20 leaving 18 is 90% loss.
2 from 20 is a 10% loss. What's wrong with the formula?
#include <stdio.h>
#include <stdlib.h>
#define ex exit(EXIT_FAILURE)
int main (int argc, char *argv[]) {
if (argc!=3) {
puts("beta usage error");
ex;
}
double x,y;
x=strtod(argv[1],NULL);
y=strtod(argv[2],NULL);
double percent(double a,double b) {
double per;
per=(a-b)*100/a;
return per;
}
printf("%.2f",percent(x,y));
return 0;
}