I have got a problem with a program I just made using a C compiler.
The problem is that no matter what input I give, the answer is always 0.
Please help.
//program starts here
#include<stdio.h>
void main()
{
int line1,line2;
double pr,rate,ti,SI;
clrscr();
for(line1=0;line1<80;line1++)
{
printf("%c",'-');
}
printf("\n\t\t\tFind Simple Interest\n");
for(line2=0;line2<80;line2++)
{
printf("%c",'-');
}
printf("\nPlease enter the principle\n");
scanf("%d",pr);
printf("\nPlease enter the rate of interest\n");
scanf("%d",rate);
printf("\nPlease enter the time period\n");
scanf("%d",ti);
SI=(pr*rate*ti)/100;
printf("The simple interest is ");
printf("%d",SI);
getch();
}
//program ends here
#include <stdio.h>
int main()
{
...
/* get loan principle, rate, and duration */
printf( "\nPlease enter the principle\n" );
scanf( "%lf", &pr );
printf( "\nPlease enter the rate of interest\n" );
scanf( "%lf", &rate );
...
/* get rid of that left-over newline in the input after using scanf() */
while (getchar() != '\n');
/* calculate and display the interest */
SI=(pr*rate*ti)/100.0;
printf( "The simple interest is %f.\n", SI );
/* keep the console window open long enough to see the program run */
printf( "Press ENTER to continue..." );
while (getchar() != '\n');
return 0;
}
Notice also that I didn't use that getch() function from <conio.h>.
The main() function returns type int.
Also, please use [code] tags.
[edit] Here's a plug for using readable variable names, also. For example, why not name the principle 'principle', instead of just 'pr'.