Thread: Novices loop trouble

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    2

    Novices loop trouble

    This is a homework assignment, and I do have permission to get help as long as the code is not written for me. The inner loop is working correctly and procucing 6 lines of correct calculations to correspond with my t values; however, I cannot get it to run back through the outer loop for the other 4 values of "i". I need it to run back through the outer loop for i= .06, .07, .08, .09, and .10. Can anyone tell me where I am messing up?

    I am using MS Visual C++ but am writing in C.

    Thank you,
    Jon

    Code:
    ----------------------------------------------------------------------------------
    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    {
           int p=100000, t=5, e;
           double  m, a, z, y, i=.06;
    	
    	
           printf("                           Mortgage Payment Plan\n\n");
           printf("Princ.     Int.      Rate      Dur.    Monthly     Total\n");
           printf("                                    (years)  Pay.          pay.\n\n");
    	while (i<=0.10){
    	         while (t<=30) {
    		e=t*12;
    		z=(1/(1+i/12));
    		y=pow(z, e);
    		m=(i/12)*p/(1-y);
    		a=m*t*12;
    		printf(" %d %.2lf %2.d %8.2lf %.2lf\n", p, i, t, m, a);
    		t=t+5;
    		}
    	i=i+.01;
    	}	
    	return 0;
    }
    ------------------------------------------------------------------------------------
    Last edited by jdlaw1; 09-06-2003 at 01:20 PM.

  2. #2
    Registered User Eigenvalue's Avatar
    Join Date
    Aug 2002
    Posts
    21
    You need to reset t to 5 after you exit out of the inner while loop. You can place it before or after you incriment (sp) i by .01.
    "I'm not responsible for what other people think I am able to do." -- Richard Feynman

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    2
    Thank You!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rewriting a for loop as a while/do-while loop
    By Ashfury in forum C++ Programming
    Replies: 7
    Last Post: 04-27-2007, 02:20 PM
  2. loop the loop - feeling foolish
    By estos in forum C Programming
    Replies: 2
    Last Post: 04-07-2007, 02:45 AM
  3. loop needed also how to make input use letters
    By LoRdHSV1991 in forum C Programming
    Replies: 3
    Last Post: 01-13-2006, 05:39 AM
  4. trouble with a for loop with an if statement nested in
    By phoenix-47 in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2005, 04:24 PM
  5. I need help as soon as possible.
    By hyrule in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 05:49 PM