Solved

C++ Consule Program

Posted on 2013-06-24
7
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 9

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.
Suggested Courses

623 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