Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Arguments {
- // milli-dollars ( $15 = 15000)
- starting_value: i64,
- // milli-dollars
- contrib: i64,
- // percentage in milli-percent ( 13% = 13_000, 100% = 100_000 )
- apr: i64,
- // deci-cents and milli-percent gives us a maximum balance near 922 billion dollars before we overflow
- contrib_years: usize,
- // deci-cents
- withdraw_amount: i64
- }
- struct Balance {
- // deci-cents
- value: i64
- }
- fn main() {
- let args = Arguments {
- starting_value: 16000_00_0,
- contrib: 1200_00_0,
- apr: 5_000,
- contrib_years: 20,
- withdraw_amount: 7100_00_0,
- };
- let months = args.contrib_years * 12;
- let mpr = args.apr/12;
- println!("Final monthly milli percentage is {}", mpr);
- let mut balance = Balance {
- value: args.starting_value
- };
- let mut year = 0;
- for i in 1..months+1 {
- // apply last months percentage first
- let interest = (balance.value * mpr) / 1_00_000;
- // add this months contribution
- let new = balance.value + interest + args.contrib;
- //println!("{}. Increase by {} and contribute {} makes about {}.", i, interest as f64 / 1000f64, args.contrib as f64 / 1000f64, new as f64 / 1000f64);
- balance.value = new;
- if i % 12 == 0 {
- println!("Year {} : ${}.{}", i/12, balance.value / 1000, balance.value%1000);
- }
- }
- println!("Max balance is ${}.{}", balance.value / 1000, balance.value%1000);
- // start burn down
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement