Hello ladies and gentlemen,

This is the program:

/* berekening_kapitaal.cpp : Defines the entry point for the console application.*/


#include <iostream.h>

void main(void)                     
{ 
    short int per = 0, tijd = 0;                                             
    float begink = 0, interest = 0, perc = 0, tot_int = 0, eindk = 0, kapitaal = 0;


    cout << "Als het begin kapitaal gelijk is aan: "; 
    cin >> begink; cin.get();
    cout << "En het percentage is ";
    cin >> perc; cin.get();
    cout << "Over een periode van: ";
    cin >> per; cin.get();

    tot_int = interest;
    eindk = kapitaal;

        while (tijd < per)
        {
        interest = (kapitaal * perc) / 100;
        kapitaal = kapitaal + interest;
        tijd ++;
        }

    cout << "Dan is het eindkapitaal na " << per << " jaar gelijk aan "   << eindk << " Euro " << endl;
    cout << "De samengestelde intresten bedragen dan " << tot_int << " %" << endl;

    cin.get();
}

The problem is that when I enter values for begink, interest and per, and try to calculate << eindk << and << tot-int <<!

My iteration does not function, can someone help me in explaining what I'm doing wrong in that iteration!

Thanks for the help,

Edited 3 Years Ago by pyTony: fixed formating

You set tot_int = interest, which sets tot_int to zero and you set eindk = kapitaal, which sets eindk to zero. tot_int and eindk never change to any other value. If you are wanting to print out the value of interest and kapitaal, just replace the tot_int with interest and eindk with kapitaal in the cout stream. If you want to keep tot_int and eindk in addition to interest and kapitaal, they need to be assigned values somewhere. You can either put them in the while loop or assign them values once you exit the while loop. But they must be updated prior to printing them out. Also, when initializing a float variable, it is best to initialize it to a float value. Instead of "float begink = 0", for example, it is best to have "float begink = 0.0". Sometimes this can create problems when you run your program.

Thanks for the tips DoubleShot, I'll surely will try them out :D

Thing is, in 'cin' can enter the 'begink' and this will automatically put the same amount into 'eindk'

Same for 'interest' into 'tot_int'

What I have to do is, calculate the total amount of money and interest after a certain period, wich is represented by 'per' And that was the problem, Ive allready changed this:

tot_int = interest;
eindk = begink;

while (tijd < per)                                   {
        interest = (eindk * perc) / 100;
        eindk = eindk + interest;
        tijd ++;
        }

Now, eindk is calculated in the correct manner, I only need to change it for the tot_int wich still remains at zero :o

Again, thanks for the tips, Ive allready corrected the initialization for the float variables.

A big thanks to fahad aswell for the mail you send me, I'll check it out and let you know what happend ok ;)

I'll let you guys now how it turns out by tomorrow ok!

Edited 3 Years Ago by happygeek: fixed formatting

@ DoubleShot and fahad,

Solution to the problem was:

tot_int = interest;
    eindk = begink;



while (tijd < per) 
                     {
                      [COLOR=DarkOrange]tot_int[/COLOR] = (eindk * perc) / 100;
                      eindk = eindk + [COLOR=DarkOrange]tot_int[/COLOR];
                      tijd ++;
                     }

Problem was that I tought once you put 'interest' into 'tot_int' and the same for 'begink' into 'eindk', they would automatically be adjusted to the new value, unfortunatly that wasn't the case and I had to use eindk and tot_int in the iteration :o

Anyway, thanks again for the help guys, it was due to what you guys wrote and said that I found the solution :D

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.