Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is the error in the line of ci=?

+3 votes
asked Jan 14, 2025 by Ankit Yadav (150 points)
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    int p,r,t;
    float si,ci;
    printf("Enter principal\n");
    scanf("%d",&p);
    printf("Enter rate\n");
    scanf("%d",&r);
    printf("Enter time\n");
    scanf("%d",&t);
    si=(p*r*t)/100;
    printf("simple interest %f\n",si);
    ci=p*pow((1+r/100),t);
    printf("compound interest %f",ci);
    return 0;
}

1 Answer

+1 vote
answered Jan 15, 2025 by Peter Minarik (101,340 points)
r / 100

is an integral division, meaning only the integral (no fractions) part is used in this calculation. E.g. 123/100 = 1 (and 0.23 is throws away).

You probably want to do a floating point division here instead:

r / 100.0

Or r / 100.0f, (notice the 'f' suffix) if you want to explicitly match the type float, otherwise the compiler will transform the double 100.0 into a float automatically.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...