Computing.Net > Forums > Programming > Simple C Program - Does not compute

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple C Program - Does not compute

Reply to Message Icon

Name: Kendra
Date: September 23, 2003 at 17:12:58 Pacific
OS: xp
CPU/Ram: 512
Comment:

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." );

}



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: September 23, 2003 at 18:02:42 Pacific
Reply:

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


0

Response Number 2
Name: Kendra
Date: September 23, 2003 at 18:46:27 Pacific
Reply:

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).


0

Response Number 3
Name: Chi Happens
Date: September 23, 2003 at 19:08:07 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


assembly trouble Onunload of a popup. Lett...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Simple C Program - Does not compute

simple C++ compile problem in Linux www.computing.net/answers/programming/simple-c-compile-problem-in-linux-/1282.html

C Program Simple Question (HELP...) www.computing.net/answers/programming/c-program-simple-question-help/10559.html

newbie needs help in simple C++ Program www.computing.net/answers/programming/newbie-needs-help-in-simple-c-program/23.html