From 123aa2822c5b3b629da946fdb60f7e5b6faac8df Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Wed, 3 Aug 2022 14:47:26 -0700 Subject: [PATCH] [example] Simple interest calculation. --- examples/interest/.gitignore | 2 ++ examples/interest/README.md | 8 ++++++++ examples/interest/inputs/interest.in | 4 ++++ examples/interest/program.json | 10 ++++++++++ examples/interest/src/main.leo | 8 ++++++++ 5 files changed, 32 insertions(+) create mode 100644 examples/interest/.gitignore create mode 100644 examples/interest/README.md create mode 100644 examples/interest/inputs/interest.in create mode 100644 examples/interest/program.json create mode 100644 examples/interest/src/main.leo diff --git a/examples/interest/.gitignore b/examples/interest/.gitignore new file mode 100644 index 0000000000..b28696155d --- /dev/null +++ b/examples/interest/.gitignore @@ -0,0 +1,2 @@ +outputs/ +build/ diff --git a/examples/interest/README.md b/examples/interest/README.md new file mode 100644 index 0000000000..c9fb67bcfc --- /dev/null +++ b/examples/interest/README.md @@ -0,0 +1,8 @@ +# interest.aleo + +## Build Guide + +To compile this Aleo program, run: +```bash +aleo build +``` diff --git a/examples/interest/inputs/interest.in b/examples/interest/inputs/interest.in new file mode 100644 index 0000000000..96576291e9 --- /dev/null +++ b/examples/interest/inputs/interest.in @@ -0,0 +1,4 @@ +// The program input for interest/src/main.leo +[main] +capital: u32 = 80u32; +rate: u32 = 5u32; // 5% diff --git a/examples/interest/program.json b/examples/interest/program.json new file mode 100644 index 0000000000..90056fcb88 --- /dev/null +++ b/examples/interest/program.json @@ -0,0 +1,10 @@ +{ + "program": "interest.aleo", + "version": "0.0.0", + "description": "", + "development": { + "private_key": "APrivateKey1zkp6QSDYHfL4Tr54dKXXxSwZWVpm1Ro3feYgpvAampgNmKu", + "address": "aleo1lwxu6nluvjt6hu0gurjsph23wlvyxkut59r757szma2s9mrljggsvue3n4" + }, + "license": "MIT" +} diff --git a/examples/interest/src/main.leo b/examples/interest/src/main.leo new file mode 100644 index 0000000000..3ca31a7e7a --- /dev/null +++ b/examples/interest/src/main.leo @@ -0,0 +1,8 @@ +// The 'interest' main function. +function main(capital: u32, public rate: u32) -> u32 { + let amount: u32 = capital; + for i:u8 in 0u8..10u8 { // accrue for 10 periods + amount += amount * rate / 100u32; // round down + } + return amount; +}