'output is wrong if i am putting value of principal=100, rate = 4, year=1 then simple interest will be 4 [closed]

#include <stdio.h>

int main()
{
  float principle;
  float rate;
  float year;
  float si = (principle*rate*year)/100;

  printf("what is the principal amount\n");
  scanf("%f", &principle);
  printf("what is the rate\n");
  scanf("%f", &rate);
  printf(" and for how many years\n");
  scanf("%f", &year);
  printf("Then si is %f", si);
  return 0;
}
what is the principal amount
100
what is the rate
4
and for how many years
1
Then si is -0.000000

I am getting simple interest as 0.00000 not 4 why?

c


Solution 1:[1]

you need to calculate the simple interest after the principle, rate and year are populated

#include <stdio.h>

int main()
{
float principle;
float rate;
float year;
// float si = (principle*rate*year)/100; //wrong . you need to calculate after the principle, rate and year are populated
float si;
    printf("what is the principal amount\n");
    scanf("%f", &principle);
    printf("what is the rate\n");
    scanf("%f", &rate);
    printf(" and for how many years\n");
    scanf("%f", &year);
    si = (principle*rate*year)/100;
    printf("Then si is %f", si);
    return 0;

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 balu