Both "%.2f" and ".%2f" are incorrect, for "one" thing (scanf is not identical to printf). Input does not have precision and the decimal point preceding a directive is significant.
I'd recommend reading user input as a string and then attempting to convert. Something similar is posted in the FAQ.
[edit]That said, this may be closer to what you are trying to do.
Code:
#include <stdio.h>
int main()
{
float balance, charges, credit, limit;
int account = 0;
for ( ;; )
{
printf("Enter account number (-1 to end): ");
scanf("%d" , &account);
if ( account == -1 )
{
break;
}
printf("Enter beginning balance: ");
scanf("%f" , &balance);
printf("Enter total charges: ");
scanf("%f" , &charges);
printf("Enter total credits: ");
scanf("%f", &credit);
printf("Enter credit limit: ");
scanf("%f", &limit);
if ( credit > limit )
{
printf("Credit Limit Exceeded\n");
}
}
return 0;
}
But I'd really take the "input as string, then convert" approach. And maybe add several fflush(stdout)'s.