Solved

C++ Consule Program

Posted on 2013-06-24
7
273 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
Comment Utility
'^' 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
Comment Utility
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
Comment Utility
Hello JKR,

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

Thanks,
AJ
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:aj85
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you both for the quick response and excellent solution.  Everything finally works!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 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

12 Experts available now in Live!

Get 1:1 Help Now