vat/vatback - work with percentages
Posted: Fri Jan 29, 2016 9:20 am
The first little program asks for the percentage (e.g. for VAT) and then accepts input to calculate the total gross amount in a loop:
And this one does the calculation backwards, from gross to net substracting percentage.
Nothing fancy, but still quicker than finding the calculator and typing the whole shit in (again and again for batch operations).
Code: Select all
#include<stdio.h>
float n,p,ps,s;
int main()
{
printf("Enter percentage number for all operations: \n%% ");
scanf("%f",&p);
printf("Enter net value, press Ctrl-c to terminate: \n");
for( ; ; ) {
printf("> ");
scanf("%f",&n);
ps = (n * p)/100;
s = n+ps;
printf("%.2f + %.2f = %.2f\n", n, ps, s);
}
return 0;
}
Code: Select all
#include<stdio.h>
float n,p,ps,s;
int main()
{
printf("Enter percentage number to substract for all operations: \n%% ");
scanf("%f",&p);
printf("Enter total gross amount, press Ctrl-c to terminate: \n");
for( ; ; ) {
printf("> ");
scanf("%f",&n);
ps = (n * p)/(100 + p);
s = n-ps;
printf("%.2f - %.2f = %.2f\n", n, ps, s);
}
return 0;
}