# Interest Calculator

Recently I found myself calculating interest and interest duration, I heaven’t found any decent tool for this so I did one by myself in C++. It does nothing else but prints the numbers you were looking for right in your terminal window.

#include <iostream>
#include <sstream>
#include <iomanip>
using namespace std;

class Interest_C
{
private:

float round (float value)
{
return ((int)(value * 100 + .5) / 100.0);
}

public:

float FinalSum(float isum, float percent, float deposit, int period)
{
float SUM = isum;
int i = 0;

do {
SUM = SUM + deposit + ((SUM * percent / 100))/12; because we the interest is for a whole year
cout << i+1 << “. month” << endl;
cout.setf(ios::fixed);
cout << setprecision(0) << round(SUM) << endl;
cout << “Interest = ” << round(((SUM * percent / 100))/12) << endl;
cout << endl;
i++;
}
while (i != period);

return SUM;
}

int FinalPeriod(float isum, float percent, float deposit, float fsum)
{
float SUM = isum;
int i = 0;
do {
SUM = SUM + deposit + ((SUM * percent / 100))/12; //we have to divide by 12 because we the interest is for a whole year
cout << i+1 << “. month” << endl;
cout.setf(ios::fixed);
cout << setprecision(0) << round(SUM) << endl;
cout << “Interest = ” << round(((SUM * percent / 100))/12) << endl;
cout << endl;
i++;
}
while (SUM <= fsum);
return SUM;
}

};

struct myseps : numpunct<char> {
char do_thousands_sep() const { return ‘,’; }
string do_grouping() const { return “\3”; }
};

int main()

{
float initial, p, dep, sum;
int period;
Interest_C *Interest = new Interest_C();
cout.imbue(locale(locale(), new myseps));

{
cout << “1 – Find out the sum” <<endl;
cout << “2 – Find out the period” << endl;
cout << “0 – exit” << endl;
cout << “1 or 2? “;
getchar();

{
case ‘1’:
cout <<“Initial amount: ” ; cin >> initial;
cout <<“Interest (%): “; cin >> p;
cout <<“Monthly deposit: “; cin >> dep;
cout <<“Period (months): “; cin >> period;
if (period <= 0) period = 1;
Interest->FinalSum(initial, p, dep, period);
break;

case ‘2’:
cout <<“Initial amount: ” ; cin >> initial;
cout <<“Interest (%): “; cin >> p;
cout <<“Monthly deposit: “; cin >> dep;
cout <<“Final sum: “; cin >> sum;
Interest->FinalPeriod(initial, p, dep, sum);
break;

case ‘0’:
return 0;
break;
}
}

delete Interest;
return 0;
}

This site uses Akismet to reduce spam. Learn how your comment data is processed.
{"ft_lang_label":"__label__en","ft_lang_prob":0.51783895,"math_prob":0.9814996,"size":2313,"snap":"2022-40-2023-06","text_gpt3_token_len":688,"char_repetition_ratio":0.17236899,"word_repetition_ratio":0.3768116,"special_character_ratio":0.38478166,"punctuation_ratio":0.25055432,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99984396,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-02T23:40:13Z\",\"WARC-Record-ID\":\"<urn:uuid:9bd181c7-5d97-466f-a5b2-c4c29cde5fb5>\",\"Content-Length\":\"58732\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ed6c5067-092e-4389-8baf-3b51ccf54f4a>\",\"WARC-Concurrent-To\":\"<urn:uuid:76457cc6-5025-4cd8-8694-b69cb1f43f07>\",\"WARC-IP-Address\":\"74.208.159.170\",\"WARC-Target-URI\":\"https://blog.danielisz.org/2013/04/05/interest-calculator/\",\"WARC-Payload-Digest\":\"sha1:ZAO3MKREVDBVFR62SR74NVO7VX3RQ4QA\",\"WARC-Block-Digest\":\"sha1:MB4CPW5CTK3DCWBDTZQDCADOEHQU7UMV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764500041.2_warc_CC-MAIN-20230202232251-20230203022251-00420.warc.gz\"}"}