Solved

C++ Consule Program

Posted on 2013-06-24
7
277 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

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. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

773 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