Thread: C exercise;The time worked form

  1. #1
    Registered User
    Join Date
    Jul 2020
    Posts
    2

    C exercise;The time worked form

    I have a trouble with my home work in computer courses. Here the exercise;
    The time worked form is a cube whose axes are: year, month, day of the month.

    Fill a three-dimensional array with data from 0 to 10 for 2015 - 2020. Request to enter the calendar number dd.mm.yy and give out the number of hours worked on that day.

    Firstly i took numbers, then i gave a answer with the number or work hours,
    how I understand i need make a matrix( jne side is days, another side is months and third side is year, but i dont know how to do it
    firstly i try to train with 2 dimension array,

    when i used such formula
    Code:
    for (i = 0; i < Months; i++)
        {
            for (j = 0; j < Days; j++)
     Cal[i][j] = i,j;
    }
    
    for (i = 0; i < Months; i++)
        {
            for (j = 0; j < Days; j++)
    printf("%i", Cal[i][j]);
    the matrix was like this
    0000
    1111
    2222
    3333

    but dont like
    0123
    1
    2
    how i expect.

    i think its must be one side is months, one side is days, inside of it is hours, and somewhere is years;

    here the code what i write, its not complete exercise, need some help with solving and explaining. If you give me a links on a good books and videos for c, its will be good too,
    Code:
    //
    
    
    #include <iostream>
    #include <stdio.h>
    #include <windows.h>
    #include <conio.h>
    #include "time.h"
    #define Years 6
    #define Months 12
    #define Days 31
    
    
    
    
    
    
    int main()
    {
        srand(time(NULL));
        int y, m, d;
        int  Cal[12][31][1];
        int i, j,k = 0;
        int h = rand() % 10;
        
        //take information
        do {
            printf("Enter the year\n");
            scanf_s("%i", &y);
            if (y < 2015||y>2020)
                printf("Wrong year\n");
        } while (y < 2015 || y>2020);
        do {
            printf("Enter the month\n");
            scanf_s("%i", &m);
            if (m < 1 || m>12)
                printf("Wrong month\n");
        } while (y < 1 || m>12);
        do {
            printf("Enter the day\n");
            scanf_s("%i", &d);
            if (d < 1 || d>31)
                printf("Wrong day\n");
        } while (d < 1 || d>31);
        // give how many work hours in this day person have
        printf("For day %i month %i year %i \n", d, m, y);
        printf("You have %i work hours", h);
    
    
       
        for (i = 0; i < Months; i++)
        {
            for (j = 0; j < Days; j++)
            {
                for (k = 0; k < Years; k++)
    
    
                    k = y;
                Cal[i][j][k];
            }
        }
    
    
    }

  2. #2
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    271

    Post

    three-dimensional array
    Code:
    #include <math.h>
    #include <stdio.h>
    #include <string.h>
    
    #define maxYear 4196
    #define maxMonths 13
    #define maxDays 34
    //
    #define january 1
    #define february 2
    #define march 3
    #define april 4
    #define may 5
    #define june 6
    #define july 7
    #define august 8
    #define september 9
    #define october 10
    #define november 11
    #define december 12
    //
    double hoursOn[maxMonths][maxDays][maxYear];
    
    int main(int args, char *argv[]) {
    
        hoursOn[february][2][2016] = 8.5;
        
        printf("%0.2f\n", hoursOn[january][10][2018] );
        printf("%0.2f\n", hoursOn[february][2][2016] );
        
        return 0;
    }
    Last edited by Structure; 4 Weeks Ago at 08:01 AM.
    "without goto we would be wtf'd"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Has anyone worked with EHR before?
    By interestpaint in forum Tech Board
    Replies: 5
    Last Post: 07-06-2016, 06:35 AM
  2. how convert uint32_t time to human read form of time?
    By barracuda in forum C Programming
    Replies: 19
    Last Post: 03-21-2015, 12:29 AM
  3. First time creating a form
    By rocketman50 in forum C++ Programming
    Replies: 4
    Last Post: 05-21-2010, 01:48 PM
  4. Form Order at Run Time
    By peckitt99 in forum C++ Programming
    Replies: 0
    Last Post: 11-12-2007, 06:36 AM
  5. Has anyone worked with...
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 12-13-2001, 01:39 AM

Tags for this Thread