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;
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello JKR,
Thanks, that solved part of my issue, any ideas on the final report display?
Thanks,
AJ
Thanks, that solved part of my issue, any ideas on the final report display?
Thanks,
AJ
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);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both for the quick response and excellent solution. Everything finally works!
Open in new window