473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to stop code from infinite looping?

3
I'm having a problem with infinite looping of my code. i am new to C++ and am writing a mortgage calculator for school assignment and my instructor is of no help. I ran across the faq/chap 15 on <iostream> and attempted to input the example within my code and receive nothing but error messages since...Can someone point out to me what I'm doing wrong PLEASE.

Expand|Select|Wrap|Line Numbers
  1. /*Header Section*/
  2.  
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <math.h>
  6. #include <limits>
  7. using namespace std;
  8.  
  9. /*End Header Section*/
  10.  
  11.  
  12. int _tmain(int argc, _TCHAR* argv[])
  13. {
  14.     double LoanAmount ;
  15.     double InterestRate ;    
  16.     double TermInMonths ;
  17.     int i = 0 ;
  18.     int Years;
  19.     int quit = 0;
  20.     do
  21.     {
  22.         // input loan amount
  23.         while ((std::cout << "Enter Loan amount without decimals: ")
  24.             && (!(std::cin >> i) || i < 1 || i > 999999999)); 
  25.     } {
  26.             std::cout << "That's not a number between 1 and 999999999; ";
  27.             std::cin.clear();
  28.             std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  29.  
  30.         // input interest rate
  31.         cout << "Enter interest rate(%): (Format 5.70 for 5.70%) " ;
  32.         cin >> InterestRate;
  33.         // input mortgage term
  34.         cout << "Enter terms of mortgage in years: ";
  35.         cin >> Years;
  36.  
  37.         InterestRate = InterestRate / 100 ;
  38.         TermInMonths = Years * 12 ;
  39.  
  40.         // monthly payment calculation formula
  41.         double payment = LoanAmount * (( InterestRate/12)/(1-pow( 1 / ( ( 1 + InterestRate / 12 ) ) , TermInMonths ) ) );
  42.  
  43.         cout << "\nLoan Amount:\t$" << LoanAmount << endl;
  44.         cout << "Interest Rate:\t" << InterestRate*100 << "%" << endl;
  45.         cout << "Terms in Months:\t" << TermInMonths << endl;
  46.         // display the payment amount
  47.         cout << "Monthly Payment:\t$" <<  payment << endl;
  48.  
  49.         cout << "\n1. Enter new data" << endl;
  50.         cout << "2. Quit" << endl;
  51.         cout << "Select a choice: ";
  52.         cin >> quit;
  53.  
  54.     while ( quit != 2 );
  55.  
  56.     return 0;
  57.  
  58.     }
the errors i'm receiving are as follows:

...er.cpp(25): error C2059: syntax error : '{'
...er.cpp(25): error C2143: syntax error : missing ';' before '{'
...er.cpp(59): fatal error C1075: end of file found before the left brace '{' at 'c:\users\charles i. clay\desktop\prg 410\er\er\er.cpp(13)' was matched
1>
1>Build FAILED.

I am completely lost as i've gone over it a million times.
Jul 3 '10 #1

✓ answered by whodgson

...and simplify the (test) of the do.......while() loop [l23 - l24] so that it is more easily understood.

3 1963
weaknessforcats
9,208 Expert Mod 8TB
Your do loop is oncorrectly coded:

Expand|Select|Wrap|Line Numbers
  1. do
  2. {
  3.  
  4. }  while (test);
Now look at yours.
Jul 3 '10 #2
mrklai
3
Thank you for pointing that out...I guess I had been staring at it too long to see that.
Jul 3 '10 #3
whodgson
542 512MB
...and simplify the (test) of the do.......while() loop [l23 - l24] so that it is more easily understood.
Jul 8 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Andreas Paasch | last post by:
Hi there, below a little code snippet that causes me some headaches. I had a similar one working fine, until I needed to redo my code on this one page entirely. Now my problem is, that the test...
3
by: The Radiator | last post by:
I have this code, but I shall have a pause in the end. Would you plaese give me some idears to this, or/and write the code better! p = (raw_input("Password please: ")) if p == "root": print ""...
6
by: chandra.somesh | last post by:
I am having trouble understanding why the code given belows enters an infinite loop when a char is entered instead of an int. i.e.on subsequent looping ,control doesn't wait for user input and just...
6
by: RdR | last post by:
Hi, Has anyone encountered infinite looping in Q Replication? This happens when I have a source DB2 table A going to a target DB2 table B, it also happens that the samne target table B is...
9
by: Rea | last post by:
Hi eb I set some 'Stop' statements and also visual breakpoints in asp code (vbscript). I am doing that in Microsoft Script debugger. Than I refresh the original page and expect execution to halt...
1
by: Michael R | last post by:
Hi All. I'm trying to delete conditions from all the controls in my form via VBA command. This code doesn't work though: Dim frm As Form Dim myControl As Control Set frm = Forms!Customers ...
0
by: yogeeswar | last post by:
HI ALL I wrote a SP having loop, and unfortunatly I forget to write exit of loop. And then I executed the SP but the processing is going on infinitly and it is not coming out of the loop. Also I...
2
by: Bruno Rafael Moreira de Barros | last post by:
index.php --- inlcude 'application.php'; functions.php --- function test1() { trigger_error('My error'); return FALSE;
8
by: Harati | last post by:
I prepared my own player using php For this ,i want code for play(),pause(),stop(). I tried a lot with player.controls.play() but no use
4
by: sphinney | last post by:
Hi everyone. I'm creating an application inside Access 2007. The application will retrieve data from various locations on my company's network servers. Depending on the time of day, alignment of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.