Loops

This is a discussion on Loops within the C++ Programming forums, part of the General Programming Boards category; I am stuck trying to write a loop that will conitunually ask for an employee number, gross pay, tax, and ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    17

    Loops

    I am stuck trying to write a loop that will conitunually ask for an employee number, gross pay, tax, and fed tax. the loop terminates when the user types in 0 as employee number, then program displays results for each employee:

    I go this so far:

    cout <<"Enter employee number: ";
    cin >> number;
    while (number > 0)
    {
    cout.precision(2);
    cout.setf(ios::fixed | ios::showpoint);

    cout <<"Enter gross pay: $";
    cin>> grosspay;
    cout <<"Enter State tax: $";
    cin >> statetax;
    cout <<"Enter fica: $"<<"\t";
    cin >>fica;

    cout <<endl;


    I can't figure out how to loop it but keep the original employee number, meaning if someones number is 100 and the next number is 235, it won't switch the emplloyee numbers with the loop count
    Any help would be appreciated

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    well for number use an array;


    http://www.cprogramming.com/tutorial/lesson8.html


    As for the loop:

    do
    {
    cout <<"Enter employee number: ";
    cin >> number;
    while (number > 0)
    {
    cout.precision(2);
    cout.setf(ios::fixed | ios::showpoint);

    cout <<"Enter gross pay: $";
    cin>> grosspay;
    cout <<"Enter State tax: $";
    cin >> statetax;
    cout <<"Enter fica: $"<<"\t";
    cin >>fica;

    cout <<endl;
    }

    while (number != 0);
    Last edited by RoD; 11-05-2002 at 01:53 PM.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    17

    Loops

    I can't use an array, we aren't allowed. Plus i dont' know the set number of employees. How do I get each employee number and info to appear, but on seperate lines once the lopp is terminated?

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    you would, if useing, output each part of the array with the "\n" or endl; function....


    Are you allowed to use vectors?

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    17

    Loop

    No, I can't use vectors
    I thought this would be fairly simple but I am stuck on showing the data after the termination of the loop

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Given the constraints of your assignment, the only thing to do that I can see is to store the data into one long string. That is, concatenate each new employee number plus financial data to a single string.

    This will require some type of delimiting in order to produce a "line feed" between employees in the display code not to mention the separation of data elements for each.

    This will make your loop rather bulky, but, off the top of my head, seems workable. (Just running an idea up the flagpole here...)

    P.S. On a 32-bit Windows system, a string may occupy well over four billion bytes, so the number of employees shouldn't pose a real problem.

    P.P.S. You needn't include setprecision() and 'fixed' within the loop. Once set, you must unset them to implement a change. 'setwidth()' is the rascal that holds for only one element.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  7. #7
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    Are you supposed to use a FILE???
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Thought about that one, too.

    (Actually, my first thought. Unfortunately, all we've got to work with is what we don't have to work with. We need more input! )

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple thread for loops
    By lehe in forum C++ Programming
    Replies: 12
    Last Post: 03-29-2009, 12:01 PM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:18 AM
  3. recoursion or loops?
    By Mecnels in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2002, 11:09 AM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 02:44 AM

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