Stránka 1 z 1

C++ nefunguje

Napsal: stř 21. lis 2012, 11:16
od acerr
Ahoj, program by měl vypočítat za kolik let budou Cleo dožene Daphne a pak vypsat obě hodnoty ...
Daphne má úrok 10%, Cleo 5%

PROČ TO NEJDE?

Kód: Vybrat vše

#include <iostream>
int main()
{
    using namespace std;
    double daphne = 100 ;
    double cleo = 100;
    double interest_daphne = 0.10 * daphne;
    double interest_cleo = 0.05 * cleo;

    int years = 0;

    while (cleo <= daphne)
    {
        daphne += interest_daphne;
        cleo += interest_cleo;
        ++ years;
         cout << cleo << " " <<  daphne << endl;


    }

    cout << cleo << " " <<  daphne << endl;

    cout << years;


    return 0;
}


Re: C++ nefunguje

Napsal: stř 21. lis 2012, 11:24
od malli
Já bych řekl, že když daphne má větší úrok než cleo a oba mají výchozí bod stejný (tzn. hodnotu 100) tak cleo nikdy nedožene daphne...

Re: C++ nefunguje

Napsal: stř 21. lis 2012, 11:25
od acerr
tak sem to přepsal - byla tam malinká chybička

Kód: Vybrat vše

#include <iostream>
int main()
{
    using namespace std;
    double daphne = 100 ;
    double cleo = 100;
    double interest_daphne = 0.10 * daphne;
    double interest_cleo = 0.05 * cleo;

    int years = 0;

    while (cleo <= daphne)
    {
        daphne += interest_daphne;
        cleo += interest_cleo;
        interest_cleo = 0.05 * cleo;

        ++ years;


    }

    cout << "Cleo ma zustatek: " << cleo << "  Daphne ma zustatek: " <<  daphne << endl;

    cout << "Tento vysledek je po: " << years;


    return 0;
}

Re: C++ nefunguje

Napsal: stř 21. lis 2012, 11:26
od acerr
byla v tom, že sem nezvyšoval Clein složený úrok