Thread: float; double; int

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    9

    float; double; int

    I can not enter dollar amounts with decimals at chk amt. I can't use float or double chk[SIZE] instead of int chk[SIZE]. What can I do?

    #include <iostream.h>
    #include <math.h>
    #include <iomanip.h>

    //Lyanette Scott CIS120

    int main()
    {
    float b;
    const int SIZE=100;
    int chk[SIZE];
    float dep;
    int totchk=0;
    int numchk;
    float nbal;

    cout << " Program to compute simple interest an amount\n"<< endl;
    cout << "Enter the amount of the deposit ( no $ or comma)"<< endl;
    cin >> dep;
    cout <<"Beginning balance" << endl;
    cin>> b;
    cout <<"How many checks for deposit" << endl;
    cin>> numchk;

    for (int i=1; i<=numchk; ++i)

    {
    cout<< "chk amt (enter zero when complete)"<<i<< ":" ;//checks
    cin >> chk[i];
    totchk += chk[i];
    if (chk[i]==0) goto next;

    }
    next:cout << "Total amt in Checks: \t$"<<totchk<<endl;

    nbal=(b+dep)-(totchk+30);

    cout << "Available balance: \t$"<< nbal<< endl;

    return 0;

    }


    Please
    HELP!!!!!!!!

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> What can I do?

    1. Learn to use code tags!

    2. Think of your values as integer numbers of cents, and scale accordingly. $1.00 = 100c.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Don't use goto
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> Don't use goto

    ! Because it wasn't formatted, I didn't bother reading the code - wow, I haven't seen one of those for years.

    <fx> whistles loudly

    Here, come and look at this guys!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    lurker
    Guest
    Do you really need the checks to be in an array? At this point, you aren't re-displaying the check amounts, so you can just use a double variable to get the amounts. Also, since you are asking for the number of checks, the user shouldn't have to enter zero to finish. Once the number of checks has been entered, the loop should end (getting rid of the goto). Something like this:

    Code:
    double chkamt; //instead of int chk[SIZE];
    
    cout <<"How many checks for deposit" << endl;
    cin>> numchk;
    
    for (int i=1; i<=numchk; ++i)
    
    {
    cout<< "chk amt "<<i<< ":" ;//checks
    cin >> chkamt;
    totchk += chkamt; 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NEED HELP READING FILE and PRINTING
    By geoffr0 in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 05:26 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  4. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM