vendredi 2 février 2018

A very simple C++ code that doesn't work

So I was reviewing some old programming notes and found that this code didn't work and I kind of just skiped over it... So after i have looked at it multiple times, i still think it right. No Idea where is wrong. Would appreciate if you guys could tell me where the mistake is.

#include <iostream>
#include <cmath>
using namespace std;

double raiseToPow(double x, int power);

int main()
{

    int Inv = 100;
    int year = 1;
    double SI = Inv * (1 + 0.1) * year;
    double factor = raiseToPow(1.05, year);
    double CI = Inv * factor;

    while(SI > CI)
        year++;

    cout << "year is " << year;

    return 0;
}

double raiseToPow(double x, int power)
{
    double result;
    int i;
    result =1.0;
    for (i=1; i<=power;i++)
    {
        result = result*x;
    }
    return(result);
}

Aucun commentaire:

Enregistrer un commentaire