• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Mar 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. struct Arguments {
2.     // milli-dollars ( \$15 = 15000)
3.     starting_value: i64,
4.     // milli-dollars
5.     contrib: i64,
6.     // percentage in milli-percent ( 13% = 13_000, 100% = 100_000 )
7.     apr: i64,
8.     // deci-cents and milli-percent gives us a maximum balance near 922 billion dollars before we overflow
9.     contrib_years: usize,
10.     // deci-cents
11.     withdraw_amount: i64
12. }
13.
14. struct Balance {
15.     // deci-cents
16.     value: i64
17. }
18.
19. fn main() {
20.     let args = Arguments {
21.         starting_value: 16000_00_0,
22.         contrib: 1200_00_0,
23.         apr: 5_000,
24.         contrib_years: 20,
25.         withdraw_amount: 7100_00_0,
26.     };
27.
28.     let months = args.contrib_years * 12;
29.     let mpr = args.apr/12;
30.     println!("Final monthly milli percentage is {}", mpr);
31.
32.     let mut balance = Balance {
33.         value: args.starting_value
34.     };
35.
36.     let mut year = 0;
37.     for i in 1..months+1 {
38.         // apply last months percentage first
39.         let interest = (balance.value * mpr) / 1_00_000;
40.         // add this months contribution
41.         let new = balance.value + interest + args.contrib;
42.         //println!("{}. Increase by {} and contribute {} makes about {}.", i, interest as f64 / 1000f64, args.contrib as f64 / 1000f64, new as f64 / 1000f64);
43.         balance.value = new;
44.
45.         if i % 12 == 0 {
46.             println!("Year {} : \${}.{}", i/12, balance.value / 1000, balance.value%1000);
47.         }
48.     }
49.
50.     println!("Max balance is \${}.{}", balance.value / 1000, balance.value%1000);
51.
52.     // start burn down
53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top