Can anyone help me with this code i have started it but then I got confused thanks.
Option 1: Create two-dimensional array choc_yourname[50][7] using the data in file chocolates.txt and print the values of this array on the screen
Option 2: Calculate the average quantity of sold chocolates per day and per week. Calculate the standard deviation for the whole sales matrix, and the standard deviation per day and per week.
Option 3: Identify which week (out of 50 weeks) produced the largest sales of chocolates and which day (out of 7 days) produced the largest sale of chocolates. For each week, calculate the number of days more than 20 chocolates were sold.
Option 4: Enable the user to modify chocolates.txt. The user should be able to change any element of the array, and also to insert new rows in the array. The change should be updated in a file called chocolates2.txt

{#include <stdio.h>
#include <stdlib.h>

int main()
{

   int choc[50][7],i,j;
   FILE *fp;

   // printf("Enter the name of file you wish to see\n");
   //gets("file_name");

   fp = fopen( "chocolate.txt","r");

   for (i=0; i<=50-1; i++)
           for (j=0; j<=7-1; j++)
               fscanf(fp,"%d",&choc[i][j]);
   for (i=0; i<=50-1; i++){
     for (j=0; j<=7-1; j++){

               printf ("%d ",choc[i][j]);
     }
     printf("\n");
   }
return 0;
}

While I'm waiting for the text file snippet

for (i=0; i<=50-1; i++)
for (j=0; j<=7-1; j++)
{}

//should be

for (i=0; i < 50; i++)
for (j=0; j < 7 ; j++)
{}

36 38 41 52 33 102 67
21 22 26 78 112 55 6
46 47 52 77 53 29 39
11 92 65 55 84 77 25
12 6 5 125 78 99 58
58 77 49 36 35 85 78
12 54 88 93 19 15 77
80 25 24 29 78 22 21
15 15 15 15 15 15 15
36 87 0 55 89 11 56
61 12 54 95 35 78 77
11 15 14 78 78 78 78
15 47 48 65 98 97 25
114 117 5 5 89 12 15
10 10 10 10 45 10 10
45 48 47 65 69 69 2
154 25 26 78 73 19 44
65 68 6 202 22 25 14
18 54 95 87 69 34 58
45 8 55 98 6 78 11
44 78 9 125 5 58 7
4 12 24 59 88 64 58
15 36 35 22 57 89 1
14 15 98 96 97 22 5
45 48 26 25 23 25 11
61 65 69 68 67 66 5
11 84 85 58 56 35 26
5 448 7 445 25 95 87
9 9 9 9 9 9 8
97 8 36 54 5 98 2
16 64 7 18 55 29 77
54 8 77 9 15 29 31
66 69 67 68 69 69 12
45 45 45 88 2 1 2
11 14 15 19 18 17 21
69 6 336 5 8 7 11
15 14 15 14 15 14 15
66 23 25 29 4 87 87
6 98 158 29 36 34 25
12 0 47 5 15 18 17
123 5 129 65 69 68 45
14 19 58 54 5 44 16
23 69 59 58 21 20 21
54 58 57 58 54 56 12
36 39 26 25 24 78 89
14 22 142 19 0 0 0
59 8 99 89 15 13 15
16 49 37 25 36 8 5
14 19 65 68 123 124 265
14 15 14 48 66 66 66

So I'm assuming that a line represents a week and each integer from left to right represents days - SMTWTFS.

You should be able to sum the array elements over the array choc[50][7] by holding the day constant. example

int sunday = 0;

for (size_t i = 0; i < 50; ++i)
    sunday += choc[i][0];

Edited 3 Years Ago by gerard4143

It doesn't. It only totals Sunday's sales. If you want an average then you'll have to divide by 50 or have a running day count to divide with.

Edited 3 Years Ago by gerard4143

This article has been dead for over six months. Start a new discussion instead.