vat/vatback - work with percentages

Submitted scripts and programs
Forum rules
Your own work only.
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

vat/vatback - work with percentages

Unread post by machinebacon » 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:

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;
}
And this one does the calculation backwards, from gross to net substracting percentage.

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;
}
Nothing fancy, but still quicker than finding the calculator and typing the whole shit in (again and again for batch operations).
..gnutella..

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: vat/vatback - work with percentages

Unread post by Snap » Fri Jan 29, 2016 9:36 am

Tnaks for this, bacon. Really helpful for my invoices.

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: vat/vatback - work with percentages

Unread post by franksinistra » Fri Jan 29, 2016 10:06 am

useful stuff... thanks
rice no more.

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: vat/vatback - work with percentages

Unread post by simgin » Fri Jan 29, 2016 10:11 am

Brilliant julius , thanks!
Someone told me that I am delusional, I almost fell off my unicorn.

Post Reply