Out of loop

This is a discussion on Out of loop within the C Programming forums, part of the General Programming Boards category; Can anyone tell me how to keep the values on the text in my code unchanged, ***printf("\tAmount Borrowed=%6.2f\tRate=%5.2f per cent\n\n",amount,rate);*** ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    5

    Lightbulb Out of loop

    Can anyone tell me how to keep the values on the text in my code unchanged, ***printf("\tAmount Borrowed=%6.2f\tRate=%5.2f per cent\n\n",amount,rate);*** but the text still to be printed as a heading on each printout page?
    And are the integers and floats initialized correctly?
    Can the look of the code be improved a bit? How?
    Thanks

    Code:
    #include<stdio.h>
    
    main()
    {
    
    /*This is a program to perform*/
    /*compound interest calculation*/
    
    float amount,interest=0,rate,pay_back;
    float total_loan=0,total_paid=0,total_owing=0;
    int year=1,repay_year,page=0;
    int remainder=0;
    
    printf("Enter the amount borrowed\n");
    scanf("%f",&amount);
    
    printf("Enter the interest rate as a percentage\n");
    scanf("%f",&rate);
    
    printf("Enter the borrowing period\n");
    scanf("%d",&repay_year);
    
    printf("Enter the annual repayment\n");
    scanf("%f",&pay_back);
    
    
    /*Output for heading*/
    
         page++;
         printf("\t\tInterest Report\n");
         printf("\t\t   Page%2d\n\n",page);
         printf("\tAmount Borrowed=%6.2f\tRate=%5.2f per cent\n\n",amount,rate);
         printf("        Year  Interest     Amount          Amount\n");
         printf("              for Year     at Year End     Paid Back\n");
       	   					   
           
          
       	      for(year=1;year<=repay_year;year++)  
       	      {
       	              
                   remainder=year%5; 
                   interest=amount*rate/100;
                   amount+=interest;    /*Get the amount for the next year*/
                   total_loan+=amount;
                   total_paid+=pay_back;
                   total_owing+=total_loan-total_paid;
                   printf("\t%2d%9.2f\t%9.2f\t%9.2f\n",year,interest,amount,total_paid);
              
              if(remainder==0&&year!=repay_year)
                     {
                      page++;
                      printf("\t-------------------------------------------\n"); 
                      printf("\tTotal amount of loan  %9.2f\n",amount);
                      printf("\tTotal amount paid back%9.2f\n",total_paid);
                      printf("\tTotal owing           %9.2f\n\n\n",amount-total_paid);
                      printf("\t\tInterest Report\n");
                      printf("\t\t   Page%2d\n\n",page);
                      printf("\tAmount Borrowed=%6.2f\tRate=%5.2f per cent\n\n",amount,rate);
                      printf("        Year  Interest     Amount          Amount\n");
                      printf("              for Year     at Year End     Paid Back\n");
                     }  
                         else
                             if(year==repay_year)
                            {
                            printf("\t-------------------------------------------\n"); 
                            printf("\tTotal amount of loan  %9.2f\n",amount);
                            printf("\tTotal amount paid back%9.2f\n",total_paid);
                            printf("\tTotal owing           %9.2f\n\n\n",amount-total_paid);
           	        }
           	  			
                        
           	 }	   
     }
    Last edited by seby24; 03-05-2003 at 02:55 PM.

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Read this then edit your post.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm not exactly sure what you mean by:
    Can anyone tell me how to keep the values on the text in my code unchanged
    What do you mean? You set values, and then use printf to display them over and over, and at some point in time the values chance so the header doesn't display the same values?

    If so, just use sprintf to put the string in a buffer and just print the buffer each time.

    If not, you'll have to tell us exactly what it is supposed to do, what it does, and what it doesn't do that it should.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    5

    Thanks

    Thanks for help and sorry for poor detailes I gave (I'm new to the forum).
    sprintf was doing the job.
    Thanks a lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 12:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-19-2005, 11:30 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21