Link to home
Start Free TrialLog in
Avatar of aj85
aj85

asked on

C++ Consule Program

Hello All,

I am writing this small test application to calculate loan interest rates.  When I compile that application I am getting the error message below for this line of code:

Monthly_Payment = Rate * (1 + Rate)^N / ((1+Rate)^N -1) * Loan_Amount;

error C2297: '^' : illegal, right operand has type 'double'

All variables are of the type "double" so I do not see where this should be an issue.  Also when I comment out this code, and execute the application, it is supposed to ask for the interest input and then calculate the results and display them.  However after you enter the requested information, the window disappears instead of displaying the results in the report format.  

Below is that block of code:

      // Display results
      cout << "\n--------------------"
             << fixed << showpoint << setprecision(2)
             << "\nloan_amount: " << Loan_Amount
             << "\nAnnual Interest Rate: " << setw(8) << Rate
             << "\nNumber of Payments:   " << setw(8) << N
             << "\nMonthly_Payment:     $" << setw(8) << Monthly_Payment
             << "\nAmount Paid Back:    $" << setw(8) << Amount_Total
             << "\nInterest Paid:       $" << setw(8) << Interest_Paid
             << endl << endl;
                          return 0;
}
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, and to prevent the console window from closing, you could e.g. add a line like

string dummy;
cout << "Press Enter to exit" << endl;
getline(cin,dummy);

Open in new window

Avatar of aj85
aj85

ASKER

Hello JKR,

Thanks, that solved part of my issue, any ideas on the final report display?

Thanks,
AJ
Avatar of aj85

ASKER

Sorry, I did not see your response to that question.  However I have added that code, and the results are the same.  Once I enter the information and go to the next line, the results are flashed quickly, then the window is closed.
Weird, that should work. An alternative would be to use

string dummy;
cout << "Type 'exit' to exit" << endl;

while (dummy != "exit") getline(cin,dummy);

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aj85

ASKER

Thank you both for the quick response and excellent solution.  Everything finally works!