Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Please see below. I only want the "credit limit exceeded" to print if the ending balance (endbal) is greater than the credit limit (limit). Currently, it always prints out. I think my problem my be in my "if" statement. Please advise.
Any help would be greatly appreciated.
#include <stdio.h>int main ()
{
int account; /* Customer's account number */
int beginbal; /* Beginning balance */
int charges; /* Monthly charges */
int credits; /* Monthly credits */
int limit; /* Credit limit */
int endbal; /* Ending balance */printf( "Enter the account number (-1 to end):\n" );
scanf( "%d", &account );printf( "Enter the beginning balance:\n" );
scanf( "%d", &beginbal );printf( "Enter the total charges: \n" );
scanf( "%d", &charges );printf( "Enter the total credits: \n" );
scanf( "%d", &credits );printf( "Enter the credit limit: \n" );
scanf( "%d", &limit );endbal = beginbal + charges - credits;
if ( endbal > limit );
printf( "Account number: %d\n", account);
printf( "Credit limit: %d\n", limit);
printf( "Balance: %d\n", endbal);
printf( "Credit Limit Exceeded." );}

you have serious issues.
i will only address the one you asked about.
if(endbal > limit); <-- whoa, that's wrong.
change it to
if(endbal > limit)
{
printf( "Account number: %d\n", account);
printf( "Credit limit: %d\n", limit);
printf( "Balance: %d\n", endbal);
printf( "Credit Limit Exceeded." );
}otherwise nothing is happening when endbal > limit because ; ends the line.
Chi Happens

Thanks Chi. I got it run now. Though I must admit you scared me with the "you have serious issues" comment. I hope the program will be acceptable. This is an intro to C class (obviously).

Glad to help, sorry about the scare, but...
well, your program does not work right.
what happens if you enter -1 (to stop as you indicate)?
nothing.
you have not coded that.
you probably are supposed to loop the input/output until they enter in -1, right?
address that before you turn in the assignment.
Chi Happens

![]() |
assembly trouble
|
Onunload of a popup. Lett...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |