arrays and for loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Learner21
    New Member
    • Mar 2008
    • 9

    arrays and for loop

    I want to how I can put the char array and the int array together in a for loop?

    This is what I got:

    I type this in are the variables were intialized:
    do


    for(workers = 0; workers <= NUM_NAME; workers++)
    {
    cout << "NAME " << workers + 1 << ":" << name[workers] << "\n";
    for(hours = 0; hours <= NUM_HOURS; hours++)
    cin >> workers_info[workers][hours];
    }






    break;
    The output:




    Welcome to the Work Hours Tracking System
    =============== =============== ===========
    A - Enter work hours for individual worker
    B - Display report for individual worker
    C - Display report for all workers
    E - Exit
    Please make a selection:
    c
    Work Hours Report:
    NAME 1:Mary Johnson
    c
    NAME 2:Jason Garcia
    NAME 3:Roy Williams
    NAME 4:Jane Rose
    NAME 5:╠╠╠╠╠╠╠╠♦
    Press any key to continue . . .



    and I need a code or a psuedo code to make the output look like this:

    Welcome to the Work Hours Tracking System
    =============== =============== ===========
    A - Enter work hours for individual worker
    B - Display report for individual worker
    C - Display report for all workers
    E - Exit

    Please enter your selection : C


    Work Hours Report:

    NAME Mon Tue Wed Thu Fri

    Mary Johnson 4 3 4 4 0
    Jason Garcia 5 5 5 4 0
    Roy Williams 5 5 5 5 0
    Jane Rose 4 0 4 3 0


    Any questions of what is written let me know

    Thanks
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    How are your arrays defined?

    Your code has them a two-dimensional array and I expect that is not accurate.

    Comment

    • Learner21
      New Member
      • Mar 2008
      • 9

      #3
      Originally posted by weaknessforcats
      How are your arrays defined?

      Your code has them a two-dimensional array and I expect that is not accurate.

      Well these are my variables for them:

      #define NUM_NAME 4
      #define NUM_HOURS 5

      int work_hours[4][5] = { {4, 3, 4, 4, 0},
      {5, 5, 5, 4, 0},
      {5, 5, 5, 5, 0},
      {4, 0, 4, 3, 0}};
      char name[4][13] = { {"Mary Johnson"},
      {"Jason Garcia"},
      {"Roy Williams"},
      {"Jane Rose"}};

      int hours = 0;
      int workers = 0;
      int workers_info[NUM_NAME][NUM_HOURS];



      honestly I am lost I really need some help please I need some help

      Thanks

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        This code:
        Originally posted by Learner21
        for(workers = 0; workers <= NUM_NAME; workers++)
        {
        cout << "NAME " << workers + 1 << ":" << name[workers] << "\n";
        for(hours = 0; hours <= NUM_HOURS; hours++)
        cin >> workers_info[workers][hours];
        }
        will ask for 5 names and 6 hour entries for each name. It should be asking for 4 names and 5 hour entries for each name.

        Those loops should be using < rather than <= as the test.

        Comment

        • Learner21
          New Member
          • Mar 2008
          • 9

          #5
          Originally posted by weaknessforcats
          This code:


          will ask for 5 names and 6 hour entries for each name. It should be asking for 4 names and 5 hour entries for each name.

          Those loops should be using < rather than <= as the test.


          Thanks so much hopefully you can help me with getting the hours to show up and only press the C once to have the whole report to show up. This is what the output looks like this:

          Welcome to the Work Hours Tracking System
          =============== =============== ===========
          A - Enter work hours for individual worker
          B - Display report for individual worker
          C - Display report for all workers
          E - Exit
          Please make a selection:
          c
          Work Hours Report:
          NAME 1:Mary Johnson
          0012FEB4
          0012FEC8
          0012FEDC
          0012FEF0
          0012FF04
          c
          NAME 2:Jason Garcia
          0012FEB4
          0012FEC8
          0012FEDC
          0012FEF0
          0012FF04
          NAME 3:Roy Williams
          0012FEB4
          0012FEC8
          0012FEDC
          0012FEF0
          0012FF04
          NAME 4:Jane Rose
          0012FEB4
          0012FEC8
          0012FEDC
          0012FEF0
          0012FF04
          Press any key to continue . . .


          It should be where I could see the row of the names and then the column of hours. Thanks again

          Comment

          Working...