interactive investment program

Program 4) This program can be converted into a more flexible interactive program using scanf.

In this case, computer requests the user to input the values of the amount to be invested,interest rate and period of investments by printing a prompt message
                  Input amount,interest rate,and period
and then waits for input values. 

                                                 Program
  
main( )
 {    
     int year, period;
     float amount, inrate, value;

     printf("Input amount, interest rate, and period\n\n);
     scanf("%f %f %d", &amount, &inrate, &period);
     printf("\n");
     year = 1

     while(year <= period)
      { 
               value = amount + inrate + amount ;
               printf("%2d Rs  %8.2f\n", year, value) ;
               amount = value ;
               year = year + 1 ;
      }
    getch();
 }


Output:    Input amount, interest rate, and period
                        1000  0.14 5
                     
                            1 Rs11400.00
                            2 Rs12996.00
                            3 Rs14815.44
                            4 Rs16889.60
                            5 Rs 19524.15
                 Input amount, interest rate, and period


                         20000  0.12 7

                            1 Rs 22400.00
                            2 Rs 25008.00
                            3 Rs 28098.56
                            4 Rs 31470.39
                            5 Rs 35246.84
                            6 Rs 39476.46
                            7 Rs 444213.63


Three variables amount,inrate,and period, the computer begins to calculate the amount at the end of each year, up to 'period' and produces output as shown in program.
Note that the sacnf functions contained three variables. In such cases, care should be exercised to see that the values entered match the order and type of the variables in the list. Any mismatch might lead to unexpected results. The compiler may not detect such errors.
          

No comments:

Post a Comment