Providers
Debian Linux
System76
SDF
MinGW-W64
Verizon
Research
Search Engines
Bing
DuckDuckGo
Google
Metacrawler
SearX
Miscellaneous
Faqs and RFCs
Grokipedia
Open Directory Project
W3Schools Online Web Tutorials
Wikipedia
Multimedia
CTIS
For the Pigs Among Us
Family Photos
My House
My Photos (1999-2002?)
My Photos (2005)
Retro Computers
Minions of Mirth
Main
Criticals
Criticals (Single Player)
Ghaqua
Maps and Points of Interest
Miscellaneous
Monster Templates
Miscellaneous
Area Codes
Bard’s Tale
Dungeons & Dragons Online
My Blog
Quote of the Day
RogueBasin
Slashdot
The Adventuer’s Guild
Weather
GitHub:eprive/Z80-MBC3
Programming
Main
Across
Biorhythm
BMP Chips
Complex Roots
Magic Square
Magic Square(js)
Matrix(js)
More DOS Programs
Roll
Strip Dups (bash)
Wacky Wood-Worker
How To
Enlightenment 0.16.7.2 Startup Patch
How to Create an OS X Iconset
My RedHat Howto
SSH to VMS (Deathrow OpenVMS Cluster)
Tools
Allowable Mortgage Interest
Dates and Mileage
Day of the Year
Fun With Time
Downloads
Educational
Utilities
change.c
/************************************************************************/ /* British currency uses the following: */ /* */ /* 4 farthings = 1 penny; */ /* 12 pence = 1 shilling; */ /* 20 shillings = 1 pound. */ /* */ /* Given the above, we should be able to: */ /* add and subtract currency; */ /* find the cost for n items at the price indicated (multiply); */ /* find the cost of 1 item, given the cost of many (divide). */ /* */ /* Results will be provided in pounds, shillings, pence, and farthings. */ /************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define EOLN '\n' #define VERSION "0.2" #define VERSION_DATE "16 November 2025" enum OP_T { DONE, INIT, ADD, SUBTRACT, MULTIPLY, DIVIDE }; void printVersion(void) { printf("CHANGE Version " VERSION "\tM. Chappell\t" VERSION_DATE "\n"); printf("Compiled: " __DATE__ "\n"); return; } int getAmount(void) { /* Returns number of farthings */ int accumulator=0; int farthings=0; int pence=0; int shillings=0; int pounds=0; int c; bool valid = false; do { printf("Enter amount as pounds shillings pence farthings:\n> "); scanf("%d %d %d %d", £s, &shillings, &pence, &farthings); if ((pounds>0)||(shillings>0)||(pence>0)||(farthings>0)) { valid = true; } else { printf("Currency must greater than or equal to zero!\n\n"); } } while (!valid); while ((c=getchar())!=EOLN) ; /* Eat EOLN */ accumulator = farthings + 4 * (pence + 12 * (shillings + 20 * pounds)); return accumulator; } void printAmount(int n) { int farthings=0; int pence=0; int shillings=0; int pounds=0; pounds = n; farthings = pounds % 4; pounds /= 4; pence = pounds % 12; pounds /= 12; shillings = pounds % 20; pounds /= 20; printf("\t%d pounds, %d shillings, %d pence, %d farthings.\n", pounds, shillings, pence, farthings); return; } void printMenu(int money) { printf("\n"); printf("Your current money is:\n"); printAmount(money); printf("\n"); printf("Select from the following:\n"); printf("\n"); printf("\t1.\tInitialize.\n"); printf("\t2.\tAdd currency.\n"); printf("\t3.\tPay amount.\n"); printf("\t4.\tMultiply by a factor.\n"); printf("\t5.\tDivide into shares.\n"); printf("\t0.\tQuit.\n"); printf("\n"); return; } enum OP_T getOperation(int money) { int c, n; char buffer[1024]; printMenu(money); do { printf("Enter selection (0-5): "); fgets(buffer, 1024, stdin); n = atoi(buffer); printf("\n"); } while ((n<0) || (n>5)); return (enum OP_T)n; } int performOperation(enum OP_T op, int amt) { float operand; switch (op) { case INIT: printf("How much currency do you have?\n"); amt = getAmount(); printf("Your total is:\n"); break; case ADD: printf("How much did you receive?\n"); amt += getAmount(); printf("Your total is:\n"); break; case SUBTRACT: printf("What was the cost?\n"); amt -= getAmount(); printf("Your remaining curency is:\n"); break; case MULTIPLY: printf("What is your multiplier?\n"); scanf("%f", &operand); amt *= operand; printf("After multiplication your result is:\n"); break; case DIVIDE: printf("How many times would you like to divide the amount?\n"); scanf("%f", &operand); amt /= operand; printf("Each Share would be:\n"); break; case DONE: printf("Your ending balance is:\n"); break; } /* switch */ return amt; } int main(int argc, char **argv) { int money = 0; bool done = false; enum OP_T op; printVersion(); /* Any arguments will quit after printing the version. */ if (argc>1) { return EXIT_SUCCESS; } while (!done) { op = getOperation(money); money = performOperation(op, money); printAmount(money); if (op == DONE) { done = true; } } return EXIT_SUCCESS; }
This source has been viewed 4 times.
Wednesday, 12 August 2026
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org