Solved

array loop w/ testing

Posted on 2002-05-20
2
184 Views
Last Modified: 2010-05-18
how do I loop and test to get the schedule?
I need to test for weekday & print user time or --- ---
 array filled with:
her  0    730    530
her  1    730    530
her  5    730    530
him  2    800    600
him  3    800    600
him  6    730    530

sched[user][weekday][start][end]
 
output like:
her 730 530 730 530 ----- ----- ----- ----- ----- ----- 800 600 ----- -----
him ----- ----- ----- ----- 800 600 800 600 ----- ----- ----- ----- 730 530
my first guess  -
while (user)
if(weekday==1){mon=sched[][][start++];mon_end=sched[end];
else cout<< ' --- --- ';}
if(weekday==2){tue=sched[][][start++];tue_end=sched[end];
else cout<< ' --- --- '';}
cout << mon << mon_end << tue << tue_end;
0
Comment
Question by:jarmstro12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 7022543
THe trick is to cycle throught eh schedule and collect the start/end for each day.  This does that and will make your boss happy.

Note:  You did not provide enough details for me to work out how you are currently storing the data.  So I created a structure (SchedDataRec) that appears to match your array layout.

#include <stdio.h>
#include <string.h>

typedef struct {
     char szUser[10];
     int  nWeekday;
     int  nStart;
     int  nEnd;
} SchedDataRec;

//------------- prefill test data.  Your array will be variable length,
//------------- This is just to satisfy the criteria of the question.

SchedDataRec arSched[6] =
{
     { "her", 0, 730, 530 },
     { "her", 1, 730, 530 },
     { "her", 5, 730, 530 },
     { "him", 2, 800, 600 },
     { "him", 3, 800, 600 },
     { "him", 6, 730, 530 }
};
int gnRecCnt= 6;  // hard-coded for test purposes

void OutputForUser( char* szUser );

void main()
{
     printf("        ---Sun--- ---Mon--- ---Tue--- ---Wed--- ---Thu--- ---Fri--- ---Sat--- \n");
     printf("Name    From   To From   To From   To From   To From   To From   To From   To \n");
     printf("------- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- \n");

     OutputForUser( "him" );    
     OutputForUser( "her" );    
}

void OutputForUser( char* szUser )
{
     int nFrom[7];
     int nTo  [7];
     int j;

     for (j=0; j<7; j++ ) {
          nFrom[j]= nTo[j]= -1;
     }
     for ( j=0; j< gnRecCnt; j++ ) {
          if ( strcmp( szUser, arSched[j].szUser ) == 0 ) {
               nFrom[ arSched[j].nWeekday ] = arSched[j].nStart;
               nTo  [ arSched[j].nWeekday ] = arSched[j].nEnd;
          }
     }
     printf("%-7s ", szUser );

     for ( j=0; j< 7; j++ ) {
          if ( nFrom[j] == -1 ) printf( "---- " );
          else                  printf( "%04d ", nFrom[j] );

          if ( nTo[j]   == -1 ) printf( "---- " );
          else                  printf( "%04d ", nTo[j] );
     }
     printf("\n" );

}

-- Dan
0
 

Author Comment

by:jarmstro12
ID: 7022721
it works and its what I asked for
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMX StringGrid1->Canvas->FillRect Problem 3 221
Unable to start eclipse ? 17 177
HTTPSendRequest with WinINet delays on first call 11 120
Outlook 13 102
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question