-1

I'm trying to make an interest rate calculator. And I keep getting this on these lines

rate >> Annualr / 12.0;


payment >> (rate * pow((1 + rate), paymentnumber) / pow((1 + rate), paymentnumber) - 1)*loan;

The large equation is supposed to calculate the amount of interest accrued on a loan

"illegal, left operand has type 'double'"
"illegal, right operand has type 'double'"

#include
<iostream>
  #include
  <string>
    #include
    <cmath>
      #include
      <iomanip>
        using namespace std; void main() { double Annualr = 0.0, loan = 0.0, payment = 0.0, rate = 0.0; int paymentnumber = 0; string fullname; cout
        << "Enter the full loan ammount: "; cin>> loan; cout
          << "Enter the Annual interest rate: "; cin>> Annualr; cout
            << "How many payments have you made? "; cin>> paymentnumber; rate >> Annualr / 12; payment >> (rate * pow((1 + rate), paymentnumber) / pow((1 + rate), paymentnumber) - 1)*loan; cout
              << "Loan Ammount: " << loan << endl; cout << "Monthly Interest Rate: " << rate << endl; cout <<
              "Number of Payments: " << paymentnumber << endl; cout << "Monthly Payment: " << payment << endl; cout << "Ammount paied back: " << payment * paymentnumber << endl; cout << "Interestt paied: " << loan - (payment * paymentnumber) << endl; system( "pause"); }
  • 2
    Please post the compiler error, and please tell us which lines are 35 and 36. – PaulMcKenzie Jan 14 '15 at 22:02
  • what did you expect this line to do? `payment >> (rate * pow((1 + rate), paymentnumber) / pow((1 + rate), paymentnumber) - 1)*loan;` a double can't be bit-shifted or treated as a stream. – iwolf Jan 14 '15 at 22:02
  • 2
    Also, it is `int main()`, not `void main()`. – PaulMcKenzie Jan 14 '15 at 22:05
  • 1
    And [`using namespace std;`](http://stackoverflow.com/q/1452721/10077) and [`system("pause");`](http://stackoverflow.com/q/1107705/10077) are both abominations. – Fred Larson Jan 14 '15 at 22:09

2 Answers2

3

Fix the typos in your code as per the lines below and it should work fine.

rate = Annualr / 12;
payment = (rate * pow((1 + rate), paymentnumber) / pow((1 + rate), paymentnumber) - 1)*loan;
Mustafa
  • 1,814
  • 3
  • 17
  • 25
  • Yes, `<<` is the iostream operator. `=` is assignment. Accept the answer to mark it as resolved please. – Mustafa Jan 14 '15 at 22:32
0

Looks like you are trying to assign value to variables of type double but for whatever reason put operator>> by mistake:

rate = Annualr / 12;
payment = (rate * pow((1 + rate), paymentnumber) / pow((1 + rate), paymentnumber) - 1)*loan;
Slava
  • 43,454
  • 1
  • 47
  • 90