Solved

C++ Consule Program

Posted on 2013-06-24
7
276 Views
Last Modified: 2013-06-25
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;
}
0
Comment
Question by:aj85
  • 3
  • 3
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 450 total points
ID: 39273017
'^' is not used to calculate powers in C/C++ - that's what 'pow()' (http://www.cplusplus.com/reference/cmath/pow/?kw=pow) is for, i.e.

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

Open in new window

0
 
LVL 86

Expert Comment

by:jkr
ID: 39273040
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

0
 

Author Comment

by:aj85
ID: 39273064
Hello JKR,

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

Thanks,
AJ
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:aj85
ID: 39273077
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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 39273104
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

0
 
LVL 8

Assisted Solution

by:Subrat (C++ windows/Linux)
Subrat (C++ windows/Linux) earned 50 total points
ID: 39273699
Small modification to jkr's response....

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

do {
  getline(cin, dummy);
} while (dummy != "exit") ;
0
 

Author Closing Comment

by:aj85
ID: 39275889
Thank you both for the quick response and excellent solution.  Everything finally works!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now