Calculator Help

So I'm trying to code a compounded interest calculated and I'm having trouble with the power function. It doesn't yield the correct results, I have no idea why. Thanks for the help!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  
void compoundintrest()
{

   
    float p;
    float r;
    float n;
    float t;
    
   cout << "Please enter Principle:";
    cin >> p;
            cout << endl;
    
   cout << "Please enter rate as decimal:";
    cin >> r;
            cout << endl;
    
   cout<< "Please enter times compounded:";
    cin >> n;
                cout<< endl;
    
   cout << "Please enter years:";
    cin >> t;
            cout<< endl;
   
    cout << "result:";

    float a= p*(1+(r/n));
    float g= (n*t);
    cout << pow(a, g);
  
    
Looks fine to me. Maybe you can try double instead of float. But that shouldn't make much of a difference.
What is the current result? What is the result you expect?

pow() returns double, maybe cout has trouble dealing with this type.
Topic archived. No new replies allowed.