Newbie here, this is only my third program. I have to write a program that calculates simple interest. Then loops and does it again unless you input "-1". Seems like I've got it 98% done, just one little thing I can't get to work right. The program should stop as soon as you input "-1", but it keeps asking the other three questions before it stops.
Code:
#include <stdio.h>
/* function main begins program execution */
int main( void )
{
float principal; /* define principal variable */
float itr; /* define interest variable */
int tm; /* define term in days variable */
float rtch; /* define interest charge variable */
while ( principal != -1 ){
/* input info */
printf( "Enter loan principal (-1 to end): " );
scanf_s( "%f", &principal );
printf( "Enter interest rate:" );
scanf_s( "%f", &itr );
printf( "Enter term of the loan in days: " );
scanf_s( "%d", &tm );
/* calculate */
rtch = (principal * itr * tm) /365;
printf( "The interest charge is $%.2f\n\n\n", rtch );}
return 0;
} /* end */
BANG HEAD ON DESK for about an hour now.