|
C-Menu 0.2.9
A User Interface Toolkit
|
Installment Loan Amortization. More...
#include <locale.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>Go to the source code of this file.
Macros | |
| #define | _GNU_SOURCE |
Functions | |
| int | main (int argc, char **argv) |
| Capture the current terminal settings for later restoration. | |
| void | print_totals (Amort *) |
Variables | |
| char | month [12][4] |
| int main | ( | int | argc, |
| char ** | argv ) |
Capture the current terminal settings for later restoration.
Main function for rsh.
iloan is a trivial application to demonstrate how a command-line program can be integrated into C-Menu Form with simple file, argument, or pipe i-o.
allows the user to enter a string in cooked mode
can be used in scripts to get a single character response from a user. For example: response=$(./enterchr "Enter Y or N: ") if [ "$response" = "Y" ]; then echo "You entered Yes" else echo "You entered No" fi This function saves the current terminal settings into a global variable so that they can be restored later. It should be called before modifying the terminal settings to ensure that the original settings can be restored when the program exits or is interrupted.
allows line editing and other features writes the prompt to stderr and the user's input to stdout handles signals to ensure that the terminal settings are restored if the program is interrupted.
Positional arguments: present_value The present value of the loan (the amount borrowed). number_of_payments The total number of payments to be made. interest_rate The annual interest rate (as a percentage). payment_amount The amount of each payment. The program calculates the missing value based on the three provided values. For example, if the present value, number of payments, and interest rate are provided, it will calculate the payment amount. If the present value, interest rate, and payment amount are provided, it will calculate the number of payments, and so on. The program can be used in a non-interactive way by passing the four values as arguments, with the value to be calculated set to 0. For example, to calculate the payment amount for a $10,000 loan with a 5% annual interest rate and 60 monthly payments, you could run:
This is proof-of-concept code, and is not intended for production use. It is not designed to be robust, and does not handle all edge cases or input errors. It is intended solely to demonstrate how a simple command-line program can be integrated into C-Menu Form. In the future, more sophisticated abstractions, such as async event handlers, serialization, rpc, database, and a standardized plugin interface will be integrated into C-Menu. Feel free to modify and enhance this code as needed, but please do not use it in production without proper testing and validation. It is provided as-is without any warranty or support. Use at your own risk.
| argc | Argument count |
| argv | Argument vector |
If executed as 'rsh', this program sets the user ID and group ID to 0 (root) and then executes the user's default shell (or /usr/bin/bash if SHELL is not set) with the provided arguments. If no arguments are given, it runs the shell in interactive mode. To work properly, this program must be compiled and set with the setuid bit:
to verify proper operation:
Definition at line 30 of file amort.c.
References month, and print_totals().
| void print_totals | ( | Amort * | amort | ) |