Here is my full program. for some reason it keep giving me the credit must be greater than 0 error that i put in. i have it set for less than or equal to zero. i enter a positive number and it gives me the error. can anyone tell me what i am doing wrong. thank you.



Code:

#include <stdio.h>

 int main(void)
{

 /* Declaration of variables. */

 int x, number_of_credits, number_of_debits;
 float credits[25], debits[25];
 float current_balance, balance;
 float total_credits = 0, total_debits = 0;
 char ledger_name[20];

 /* Display of initial greeting */

 printf ("Welcome to Mike's Ledger System\n\n");

 /* Prompt for ledger account name. */

 printf ("Please enter the ledger account name:");
 scanf ("%s", ledger_name);
 fflush(stdin);

 /* Explanation of program */

 printf ("This program will allow you to enter credits and debits to the %s account.\n\n", ledger_name);

 /* Prompt to enter current balance. (current_balance >= 0) */

 do
  {

 printf ("Please enter the Trip Expenses current balance in dollars and cents:");
 scanf ("%f", &current_balance);
 fflush(stdin);

 /* Display error if current balance is less than 0 dollars. */

 if (current_balance < 0)
  printf ("Error: Beginning balance must be at least zero, please re-enter!\n\n");
 } 
 while (current_balance < 0); 

 
 /* End loop if current balance is less than 0 dollars. */

 
  current_balance = balance;

 /* Prompt for number of debits and credits to be posted */

 do
 {

 printf ("\nEnter the number of debits to post: ");
 scanf ("%i", &number_of_debits);
 fflush(stdin);

 if (number_of_debits <= 0)
  printf ("ERROR: Please enter a number greater than zero!\n\n");
 if (number_of_debits > 25)
  printf ("ERROR: Please enter a number no more than 25!\n\n");
 } 
 while (number_of_debits < 0 && number_of_debits > 25);
 do
 {

  printf ("\nEnter the number of credits to post: ");
  scanf ("%i", &number_of_credits);
  fflush(stdin);

 if (number_of_credits < 0)
 
  printf ("ERROR: Please enter a number greater than zero!\n\n");
 if (number_of_credits >25)
  printf ("ERROR: Please enter a number no more than 25!\n\n");
 } 
 while (number_of_credits < 0 || number_of_credits > 25);

 /* for loop starts which will add the credit amounts entered */

 for (x = 1; x <= number_of_credits; ++x)
 {
 

 /* Prompt for credit amount */

 
 do
 {

  printf ("Enter the amount of credit #%i: ", x);
  scanf ("%f", &credits[x]);
  fflush(stdin);

 
 if (credits[x] <= 0);
  printf ("***Credit amount must be greater than zero. Please re-enter!***\n");
 }
 while (credits[x] <= 0);

 /* new value to the total credit will be created by adding the credits */

 
 total_credits = total_credits + credits[x];
 }
 

 /*end for loop */


 /* for loop starts to enter and add up debit amounts */

 for (x = 1; x <= number_of_debits; ++x)
 {
  

 /* Prompt for debit amount */

 
 do
 {

  printf ("Enter the amount of debit #%i: ", x);
  scanf ("%f", &debits[x]);
  fflush(stdin);


 /* this loops displays a message if debit amount is greater than the balance*/

 
 if (debits[x] > current_balance);
 printf ("***Debit amount exceeds current balance!***\n");
 if (debits[x] <= 0);
 printf ("***Debit amount must be greater than zero! Please re-enter.***\n");
 } 
 

 /* loop ends when amount is greater than 0 */

 
 while (debits[x] > current_balance || debits[x] <= 0);

 /* new value to the total debit by adding the amount entered */

 
 total_debits = total_debits + debits[x];

/* this will calculate the balance and ensures the debit is less than the balance*/

 
 balance = current_balance - total_debits + total_credits;
 if (balance == 0);
 {
  

 /* if balance reaches 0, a message will be displayed and no more debits allowed */

 
 printf ("\n *** Balance is now zero. No more debit transactions can be made at this time. ***\n");
 
 number_of_debits = x;
 break;
 
 } 
 

 /* end the loop */
 

 }

 /*Calculate and display ledger balance */

 printf ("***The %s balance is $%.2f***\n", ledger_name, balance);

 /* Message displayed depends on the end balance */

 
 if (balance > 0)
  
  printf ("*** The account %s has a credit balance ***\n\n", ledger_name);
  
 if (balance == 0)
 printf ("*** The account %s is now exhausted of funds ***\n\n", ledger_name);
 
 else
 printf ("*** The account %s is now over the allotted budget ***\n\n", ledger_name);
  
 

 /* Display of ledger record */

 printf ("*** Ledger Record ***\n\n");
 printf ("%s", ledger_name);
 printf ("\nStarting Balance: %.2f\n\n", current_balance);

 for (x = 1; x <= number_of_credits; x++)
 {
 printf ("Credit #%i: %.2f\n", x, credits[x]);
 }
 for (x = 1; x <= number_of_debits; x++)
 {
 printf ("\nDebit #%i: %.2f\n", x, debits[x]);
 }
  printf ("\nEnding Balance: $ %.2f\n", balance); 
  
  
  
 return 0;
 
 }
 
 
//end main