simple interest using functions.

i was trying to make a program of calculating simple intrest using functions.

i dont know whats wrong with the program but it always shows a wrong output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream.h>
#include<conio.h>
float si(int p,int r,int t)
{
return ((p*t*r)/100.0);
}
void main()
{
clrscr();
int p,t;
float s,r;
cout<<"enter p,r,t";
cin>>p>>r>>t;
s=si(p,r,t);
cout<<s;
getch();
}


Please help.
closed account (o3hC5Di1)
Hi there,

Could you please be a little more specific?
Which output do you expect with which input, and what output is it giving you instead?

All the best,
NwN
Last edited on
Maybe he's expecting the result to a specific number of decimal places? In which case look at sprintf and the format options... But agreed would be handy to know what the expected output for a given input is.
@NwN: any input, i take, it gives me a wrong output.

For eg:
If I take p=10000
r=10
t=1
then it gives me an output of -310.73, whereas the output should be 1000.
closed account (o3hC5Di1)
Hi there,

Try using a debug-cout statement as such:

3
4
5
6
7
float si(int p,int r,int t)
{
   std::cout << "p = " << p << "\nr = " << r << "\nt = " << t << std::endl;
   return ((p*t*r)/100.0);
}


If the valuesthere are incorrect, there may be a problem with how you write them in.
You are not separating the p r and t with comma's when you input them into the program are you?
It will only work using spaces, unless you do:

1
2
char c;
std::cin << p << c << r << c << t;


All the best,
NwN
Topic archived. No new replies allowed.