gotta help me with my c prog

This is a discussion on gotta help me with my c prog within the C Programming forums, part of the General Programming Boards category; i need help witn my c programm sup guys need alil help with my c programm ..My poor progie is ...

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    gotta help me with my c prog

    i need help witn my c programm

    sup guys need alil help with my c programm ..My poor progie is acting kinda weird might be a
    programming error by me .. well if the Nbalance is
    greater than the limit it should print whats in the if () statment
    I used borland C compiler

    #include <stdio.h>

    int main()
    {
    int act, cnt;
    float balance, Tcharge, Tcredit, limit, Nbalance;
    clrscr();


    while ( cnt != -1 ) {
    printf("\nEnter account number (-1 to end ):");
    scanf("%d", &act);
    if ( act == -1)
    break;
    printf("\nEnter beginning balance: ");
    scanf("%d", &balance);
    printf("\nEnter total charge: ");
    scanf("%d", &Tcharge);
    printf("\nEnter total credits: ");
    scanf("%d", &Tcredit);
    printf("\nEnter credit limit: ");
    scanf("%d", &limit);
    }
    if ( Nbalance > limit ){
    printf("Acount: %d\n", act);
    printf("Credit limit: %d\n", limit);
    printf("Balance: %d\n",Nbalance);
    Nbalance = balance + Tcharge - Tcredit;
    printf("\nCredit Limit Exceeded");
    }

    getch();

    return 0;
    }

    Hey guys one more thing plz compile it and check my programm if its working properlly that way u will know what wrong with it c ya ...


    

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) Learn how to form correct sentences (and words). No one wants to read that butchered typing.

    2) How about you actually give a value to 'Nbalance' before you use it? That might be a good idea, huh? Nbalance has no value. Actually it does, but it's some random arbitrary number since you have fallen into one of the most basic traps for newbies: You're using a variable without initializing it. This is a "BadThing(TM)".

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Unregistered
    Guest
    also by the looks of it your while statement
    while ( cnt != -1 )
    should me
    while ( act != -1 )

    and just to make sure it goes in there (as quzah said) the vale of act could possibly be -1, no way to no so you should set it to 0 or some value before the while statement.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    I answered your question in a previous post, please don't start a new thread with the same question. If I'm thinking of someone else, please accept my appologies, but I'm pretty sure this is the same program.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assembly amature question: prog errors
    By geek@02 in forum Tech Board
    Replies: 1
    Last Post: 10-03-2008, 01:35 PM
  2. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  3. YangHui triangle print test prog?
    By toysoldier in forum C++ Programming
    Replies: 8
    Last Post: 08-20-2004, 08:46 AM
  4. Replies: 3
    Last Post: 06-29-2003, 05:50 PM
  5. an option at the end of this prog to ask if I want to run again
    By bandito9111 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2003, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21