Кажется, я не могу правильно выполнить свои операторы if в разделе «Ввод и вывод средств». Он будет работать правильно, когда число отрицательное, но когда оно положительное, оно отображает сообщение об ошибке, а затем завершает цикл и переходит к снятию.
#include <stdio.h>
int main (void)
{
int deposits = 0, totaldeposits = 0, deposited = 0, totalwithdrawals = 0, withdrawals, d = 0, w = 0;
float balance = 0, b;
printf ("Welcome to the computer banking system\n\n");
for ( b = 0; b <= balance; ++b )
{
printf ("Enter your current balance in dollars and cents:");
scanf ("%f", &b);
balance = balance + b;
if ( balance <= -1 )
{
printf ("***Beginning balance must be at least zero, please re-enter.\n\n");
balance = balance - b, --b;
}/*end of if statement*/
}/*end of for loop*/
for ( d = 0; d <= deposits; ++d )
{
printf ("\nEnter the number of deposits (0-5):");
scanf ("%i", &d);
deposits = deposits + d;
if ( deposits > 5 || deposits < 0 )
{
printf ("*** Invalid number of deposits, please re-enter.");
deposits = deposits - d;
}/*end of if statement for deposits*/
}/*end of for loop for deposits*/
for ( w <= 0; w <= withdrawals; ++w)
{
printf ("\n\nEnter the number of withdrawals (0-5):");
scanf ("%i", &w);
withdrawals = withdrawals + w, ++w;
if ( withdrawals > 5 || withdrawals < 0 )
{
printf ("***Invalid number of withdrawals, please re-enter.");
withdrawals = withdrawals - w, --w;
}/*end of withdrawals if*/
}/*end of withdrawals for loop*/
getchar;
return 0;
} /*End main*/