3rd cin getting ignored

I'm doing an Amortization code for school and my 3rd cin keeps getting ignored. Tbh, lots of my code is probably wrong. Please 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
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
  cout << setprecision(2) << fixed << showpoint;
  double L = 0;  //loan amount
  int APR = 0;
  double payment = 0.0;
  int N = 0;  //number of months
  double interest = 0.0;

  payment = L * (APR *(1+APR)^N / (((1+APR) ^N)-1);
  cout << "Enter the loan amount" << endl;
  cin >> L;
  cout << "Enter the APR as a decimal" << endl;
  cin >> APR;
  cout << "Enter the number of months" << endl;
  cin >> N;       //the cin that keeps getting skipped

  //this next stuff, idk what formulas to put in for some of them
  cout << "Loan Amount: $ " << L << endl;
  cout << "Monthly Interest Rate: " << APR/12 << endl;
  cout << "Number of Payments: " << payment << endl;
  cout << "Amount Paid Back: " << /* ??? */ <<endl;
  cout << "Interest Paid: " << /* ??? */ << endl;
  return 0;
}

Thanks :)
Last edited on
What are you entering for APR? APR is declared as an int, but the text prompting for a decimal makes it sound like you're expecting something like .25 - in which case APR should probably be a double.

See the cmath library for the pow function to raise a number to a power.
http://www.cplusplus.com/reference/cmath/pow/
Last edited on
Just like @wildblue said, you have asked the user to supply a decimal, but you provided an integer to receive the input.

The cin >> operator will stop reading at '.', and then the next cin >> will just continue reading from the remaining input text.

Another thing I'm seeing is you calculated payment before user input. Maybe you should do that after user input?
If i make the APR a double, it gives me the error "invalid operands of types 'double' and 'int' to binary 'operator'". Basically I can't make that formula work, even though that's the formula the assignment is making me use.

@wildblue the input for APR the "user" is going to enter is 0.12, which means 1 year. The "user" is also entering L to be 10000 and N is 36

The caret ^ is the bit-wise mutually-exclusive OR operator (called XOR).
It doesn't have anything to do with exponents. Take @wildblue's advice and look up std::pow.
Last edited on
closed account (iyRG3TCk)
@heyheyitscurly..
Can u tell me what kind of program are you writing ??
Topic archived. No new replies allowed.