Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A quick demonstration of working out percentages using C
- * will probably work on all other problem-orientated languages.
- * Written with Code::Blocks, tested on Windows 7 and cmd.exe
- *
- * @Author: Shaun B
- * @Version: 1.0.1 - 2013-06-14
- * @Todo: Look into floating point guides and why
- * there are rounding errors
- *
- **/
- #include <stdio.h>
- #include <stdlib.h>
- /// Function prototypes:
- int main();
- float percent (float pc);
- float taxToAdd (float number, float percent);
- /// Variables:
- float taxRate = 20.00f; // ie VAT, PAYE etc...
- float percentage = 0.00f;
- float taxToPay = 0.00f;
- float priceWithTax = 0.00f;
- int main()
- {
- float originalPrice = 59.99f;
- unsigned char pound = 156;
- percentage = percent (taxRate);
- taxToPay = taxToAdd (originalPrice, percentage);
- priceWithTax = originalPrice + taxToPay;
- printf("Tax rate set to: %.2f\%%\n", taxRate);
- printf("Original price of goods less tax: %c%.2f\n", pound, originalPrice);
- printf("Tax on goods: %c%.2f\n", pound, taxToPay);
- printf("Total payable: %c%.2f\n", pound, priceWithTax);
- printf("Fin. Press any key.");
- _getch();
- return 0;
- }
- float percent (float pc)
- {
- return (float)pc/100.00f;
- }
- float taxToAdd (float price, float percent)
- {
- return (float)price*percent;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement