Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

#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?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;

}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading