1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Help with calculating interest

Discussion in 'Software Development' started by SuitedMonkey, Feb 19, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. SuitedMonkey

    SuitedMonkey Thread Starter

    Joined:
    Nov 10, 2012
    Messages:
    51
    ok so the basics of the code is that the user enters the Principal value, the interest rate, and the number of years to let it compound. Normally pretty easy but there's a catch; I can't use the math library.

    So i did what i think is the code but there are a ton of errors that i don't understand. Any help would be appreciated!
    Code:
    #include <stdio.h>
    double calculation(double prin_val, int time, double rate)
    void main() {
            double future_val, principle_val, double int_rate; //future value, principle value, interest rate
            int time;
    
            printf("Please enter the principal value and interest rate followed by the number of periods.\n");
            scanf("%lf, %lf, %d", &principle_val, &time);
    
            calculation(principle_val, time, int_rate);
    
            printf("The future value is: %.2lf \n", future_val);
            }
    double calculation(double principle_val,int time, double int_rate){
            double fut_val;
            int_rate +=1;
            do {
                    int_rate =* int_rate;//alternative for exponents
                    time--;
            }while(time<0);
    
            fut_val = principle *int_rate;
            return fut_val;
    }
    
     
  2. andythepandy

    andythepandy

    Joined:
    Jul 2, 2006
    Messages:
    379
    There are a few basic errors in the code like operators being the wrong way around (=* instead of *=) and variables names being typed incorrectly. Below is an edited version with comments where I changed parts. This code compiles but it doesn't look like it gives the correct output, hopefully it will get you started though:

    Code:
    #include <stdio.h>
    //ADDED SEMI COLON AT END OF NEXT LINE
    double calculation(double prin_val, int time, double rate);
    int main() {
            //REMOVED SECOND DOUBLE ON NEXT LINE, UNNECESARY
            double future_val, principle_val, int_rate; //future value, principle value, interest rate
            int time;
    
            printf("Please enter the principal value and interest rate followed by the number of periods.\n");
            scanf("%lf, %lf, %d", &principle_val, &time);
    
            calculation(principle_val, time, int_rate);
    
            printf("The future value is: %.2lf \n", future_val);
            return 0;
            }
    double calculation(double principle_val,int time, double int_rate){
            double fut_val;
            int_rate +=1;
            do {
                    //CHANGED TO *= here
                    int_rate *= int_rate;//alternative for exponents
                    time--;
            }while(time<0);
    
            //CHANGED PRINCIPLE TO PRINCIPLE_VAL AS THAT IS WHAT THE VARIABLE IS CALLED
            fut_val = principle_val *int_rate;
            return fut_val;
    }
    
    
     
  3. SuitedMonkey

    SuitedMonkey Thread Starter

    Joined:
    Nov 10, 2012
    Messages:
    51
    ok that worked. but it didn't work. i'm trying to use the math library now so that i can use the pow() function. here's the code
    Code:
    double calculation(double principle_val,int time, double int_rate){
            double fut_val;//futute value
            double rand_val; //just a holding place
            int_rate +=1;
            rand_val = pow(int_rate,time);
            fut_val = principle_val * rand_val;
    
            return fut_val;
    }
    
    and here's the error i get
    Code:
    (. text+0x105) : undefined reference to 'pow'
    collect2: ls returned 1 exit status
    
    any help would be apreciated
     
  4. andythepandy

    andythepandy

    Joined:
    Jul 2, 2006
    Messages:
    379
    Have you included the math library. I think some compilers include it automatically but don't know if they all do
     
  5. SuitedMonkey

    SuitedMonkey Thread Starter

    Joined:
    Nov 10, 2012
    Messages:
    51
    yea it's #include<math.h>
    i'm using putty
     
  6. andythepandy

    andythepandy

    Joined:
    Jul 2, 2006
    Messages:
    379
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1090216

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice