Help

hi there
i am really stuck on my school project
what i like to do is to make a sales analysis program where the user need to enter the year and then the month
i have tried to make make arrays which is 2 dimentional but i am having trouble saving the data, i have tryed to make two different arrays then i dunt know how to nest a array with in another array, and how to access it. if anyone is out there i would be grateful if any can offer me any advice

thank you

Comments

  • : hi there
    : i am really stuck on my school project
    : what i like to do is to make a sales analysis program where the user need to enter the year and then the month
    : i have tried to make make arrays which is 2 dimentional but i am having trouble saving the data, i have tryed to make two different arrays then i dunt know how to nest a array with in another array, and how to access it. if anyone is out there i would be grateful if any can offer me any advice
    :
    : thank you
    :
    Saving a 2D-array of reals is quite simple, once you know how to do it. Here is a sample code, which saves a 2D-array to a text file:
    [code]
    var
    Data: array[1..10, 1..10] of double;
    f: text;
    i, j: integer;
    begin
    Assign(f, 'Filename');
    Rewrite(f);
    for i := 1 to 10 do
    begin
    for j := 1 to 10 do
    write(f, Data[i, j], ' ');
    writeln(f);
    end;
    Close(f);
    end;
    [/code]
    The order in which the loops are nested is important, because that controls the order in which the elements are listed in the file.
    The space behind each number is used to separate them. This allows you to use read() to read the individual values from a line. The code for reading is very similar, except for the write()/writeln()'s.
    If you want to store the array in a binary file, you don't need the writeln() and the spaces. Otherwise the code is the same.

    As for nesting arrays: you need to make a type-declaration of an array:
    [code]
    type
    TMyArray = array [1..10] of double;
    [/code]
    Then you can use that type as the elements of the second array:
    [code]
    var
    My2DArray = array[1..10] of TMyArray;
    [/code]

  • : : hi there
    : : i am really stuck on my school project
    : : what i like to do is to make a sales analysis program where the user need to enter the year and then the month
    : : i have tried to make make arrays which is 2 dimentional but i am having trouble saving the data, i have tryed to make two different arrays then i dunt know how to nest a array with in another array, and how to access it. if anyone is out there i would be grateful if any can offer me any advice
    : :
    : : thank you
    : :
    : Saving a 2D-array of reals is quite simple, once you know how to do it. Here is a sample code, which saves a 2D-array to a text file:
    : [code]
    : var
    : Data: array[1..10, 1..10] of double;
    : f: text;
    : i, j: integer;
    : begin
    : Assign(f, 'Filename');
    : Rewrite(f);
    : for i := 1 to 10 do
    : begin
    : for j := 1 to 10 do
    : write(f, Data[i, j], ' ');
    : writeln(f);
    : end;
    : Close(f);
    : end;
    : [/code]
    : The order in which the loops are nested is important, because that controls the order in which the elements are listed in the file.
    : The space behind each number is used to separate them. This allows you to use read() to read the individual values from a line. The code for reading is very similar, except for the write()/writeln()'s.
    : If you want to store the array in a binary file, you don't need the writeln() and the spaces. Otherwise the code is the same.
    :
    : As for nesting arrays: you need to make a type-declaration of an array:
    : [code]
    : type
    : TMyArray = array [1..10] of double;
    : [/code]
    : Then you can use that type as the elements of the second array:
    : [code]
    : var
    : My2DArray = array[1..10] of TMyArray;
    : [/code]
    :
    : thanks for the example it helped alot
    but yeah

    procedure salesdata; var count:integer;
    begin

    reset(sales);
    readln(sales ,Data[year, month]);
    write ('Please enter the appropriate year for the sales data');
    readln(useryear);
    if (useryear<1995) or (useryear >2010) then
    repeat
    writeln('please choose a year between 1995 to 2010');
    readln(useryear);
    until (useryear>=1995) and (useryear <=2010);

    begin
    count:=0;
    rewrite(sales);
    for month:= 1 to maxmonth do
    begin

    count :=count+1;
    writeln ('please enter in the Sales value for month ', count,' year ', useryear);
    readln(sales, Data[year, month]);
    writeln(sales, Data[year, month]);
    writeln(sales);
    end;
    end;
    Close(sales);
    end;
    that is my code but i cant seem to enter a sales figure, it just loops throught and i am unable to enter any values for the month, did i do something wrong?

  • : : : hi there
    : : : i am really stuck on my school project
    : : : what i like to do is to make a sales analysis program where the user need to enter the year and then the month
    : : : i have tried to make make arrays which is 2 dimentional but i am having trouble saving the data, i have tryed to make two different arrays then i dunt know how to nest a array with in another array, and how to access it. if anyone is out there i would be grateful if any can offer me any advice
    : : :
    : : : thank you
    : : :
    : : Saving a 2D-array of reals is quite simple, once you know how to do it. Here is a sample code, which saves a 2D-array to a text file:
    : : [code]
    : : var
    : : Data: array[1..10, 1..10] of double;
    : : f: text;
    : : i, j: integer;
    : : begin
    : : Assign(f, 'Filename');
    : : Rewrite(f);
    : : for i := 1 to 10 do
    : : begin
    : : for j := 1 to 10 do
    : : write(f, Data[i, j], ' ');
    : : writeln(f);
    : : end;
    : : Close(f);
    : : end;
    : : [/code]
    : : The order in which the loops are nested is important, because that controls the order in which the elements are listed in the file.
    : : The space behind each number is used to separate them. This allows you to use read() to read the individual values from a line. The code for reading is very similar, except for the write()/writeln()'s.
    : : If you want to store the array in a binary file, you don't need the writeln() and the spaces. Otherwise the code is the same.
    : :
    : : As for nesting arrays: you need to make a type-declaration of an array:
    : : [code]
    : : type
    : : TMyArray = array [1..10] of double;
    : : [/code]
    : : Then you can use that type as the elements of the second array:
    : : [code]
    : : var
    : : My2DArray = array[1..10] of TMyArray;
    : : [/code]
    : :
    : : thanks for the example it helped alot
    : but yeah
    :
    : procedure salesdata; var count:integer;
    : begin
    :
    : reset(sales);
    : readln(sales ,Data[year, month]);
    : write ('Please enter the appropriate year for the sales data');
    : readln(useryear);
    : if (useryear<1995) or (useryear >2010) then
    : repeat
    : writeln('please choose a year between 1995 to 2010');
    : readln(useryear);
    : until (useryear>=1995) and (useryear <=2010);
    :
    : begin
    : count:=0;
    : rewrite(sales);
    : for month:= 1 to maxmonth do
    : begin
    :
    : count :=count+1;
    : writeln ('please enter in the Sales value for month ', count,' year ', useryear);
    : readln(sales, Data[year, month]);
    : writeln(sales, Data[year, month]);
    : writeln(sales);
    : end;
    : end;
    : Close(sales);
    : end;
    : that is my code but i cant seem to enter a sales figure, it just loops throught and i am unable to enter any values for the month, did i do something wrong?
    :
    :
    If you want to enter data from the keyboard, you need to call readln() without any file-variables in the parameters. This will force Pascal to use the standard input, which is the keyboard.
  • [b][red]This message was edited by joiboi at 2004-7-13 4:35:21[/red][/b][hr]
    : : : : hi there
    : : : : i am really stuck on my school project
    : : : : what i like to do is to make a sales analysis program where the user need to enter the year and then the month
    : : : : i have tried to make make arrays which is 2 dimentional but i am having trouble saving the data, i have tryed to make two different arrays then i dunt know how to nest a array with in another array, and how to access it. if anyone is out there i would be grateful if any can offer me any advice
    : : : :
    : : : : thank you
    : : : :
    : : : Saving a 2D-array of reals is quite simple, once you know how to do it. Here is a sample code, which saves a 2D-array to a text file:
    : : : [code]
    : : : var
    : : : Data: array[1..10, 1..10] of double;
    : : : f: text;
    : : : i, j: integer;
    : : : begin
    : : : Assign(f, 'Filename');
    : : : Rewrite(f);
    : : : for i := 1 to 10 do
    : : : begin
    : : : for j := 1 to 10 do
    : : : write(f, Data[i, j], ' ');
    : : : writeln(f);
    : : : end;
    : : : Close(f);
    : : : end;
    : : : [/code]
    : : : The order in which the loops are nested is important, because that controls the order in which the elements are listed in the file.
    : : : The space behind each number is used to separate them. This allows you to use read() to read the individual values from a line. The code for reading is very similar, except for the write()/writeln()'s.
    : : : If you want to store the array in a binary file, you don't need the writeln() and the spaces. Otherwise the code is the same.
    : : :
    : : : As for nesting arrays: you need to make a type-declaration of an array:
    : : : [code]
    : : : type
    : : : TMyArray = array [1..10] of double;
    : : : [/code]
    : : : Then you can use that type as the elements of the second array:
    : : : [code]
    : : : var
    : : : My2DArray = array[1..10] of TMyArray;
    : : : [/code]
    : : :
    : : : thanks for the example it helped alot
    : : but yeah
    : :
    : : procedure salesdata; var count:integer;
    : : begin
    : :
    : : reset(sales);
    : : readln(sales ,Data[year, month]);
    : : write ('Please enter the appropriate year for the sales data');
    : : readln(useryear);
    : : if (useryear<1995) or (useryear >2010) then
    : : repeat
    : : writeln('please choose a year between 1995 to 2010');
    : : readln(useryear);
    : : until (useryear>=1995) and (useryear <=2010);
    : :
    : : begin
    : : count:=0;
    : : rewrite(sales);
    : : for month:= 1 to maxmonth do
    : : begin
    : :
    : : count :=count+1;
    : : writeln ('please enter in the Sales value for month ', count,' year ', useryear);
    : : readln(sales, Data[year, month]);
    : : writeln(sales, Data[year, month]);
    : : writeln(sales);
    : : end;
    : : end;
    : : Close(sales);
    : : end;
    : : that is my code but i cant seem to enter a sales figure, it just loops throught and i am unable to enter any values for the month, did i do something wrong?
    : :
    : :
    : If you want to enter data from the keyboard, you need to call readln() without any file-variables in the parameters. This will force Pascal to use the standard input, which is the keyboard.
    :

    sawi, but yeah i tryed what you told me to put just readln();
    but pascal is asking for a variable, i dunno what to do
    i put it in

    writeln ('please enter in the Sales value for month ', count,' year ', useryear);
    : : readln;
    : : writeln(sales, Data[year, month]);
    : : writeln(sales);
    : : end;


  • : [b][red]This message was edited by joiboi at 2004-7-13 4:35:21[/red][/b][hr]
    : : : : : hi there
    : : : : : i am really stuck on my school project
    : : : : : what i like to do is to make a sales analysis program where the user need to enter the year and then the month
    : : : : : i have tried to make make arrays which is 2 dimentional but i am having trouble saving the data, i have tryed to make two different arrays then i dunt know how to nest a array with in another array, and how to access it. if anyone is out there i would be grateful if any can offer me any advice
    : : : : :
    : : : : : thank you
    : : : : :
    : : : : Saving a 2D-array of reals is quite simple, once you know how to do it. Here is a sample code, which saves a 2D-array to a text file:
    : : : : [code]
    : : : : var
    : : : : Data: array[1..10, 1..10] of double;
    : : : : f: text;
    : : : : i, j: integer;
    : : : : begin
    : : : : Assign(f, 'Filename');
    : : : : Rewrite(f);
    : : : : for i := 1 to 10 do
    : : : : begin
    : : : : for j := 1 to 10 do
    : : : : write(f, Data[i, j], ' ');
    : : : : writeln(f);
    : : : : end;
    : : : : Close(f);
    : : : : end;
    : : : : [/code]
    : : : : The order in which the loops are nested is important, because that controls the order in which the elements are listed in the file.
    : : : : The space behind each number is used to separate them. This allows you to use read() to read the individual values from a line. The code for reading is very similar, except for the write()/writeln()'s.
    : : : : If you want to store the array in a binary file, you don't need the writeln() and the spaces. Otherwise the code is the same.
    : : : :
    : : : : As for nesting arrays: you need to make a type-declaration of an array:
    : : : : [code]
    : : : : type
    : : : : TMyArray = array [1..10] of double;
    : : : : [/code]
    : : : : Then you can use that type as the elements of the second array:
    : : : : [code]
    : : : : var
    : : : : My2DArray = array[1..10] of TMyArray;
    : : : : [/code]
    : : : :
    : : : : thanks for the example it helped alot
    : : : but yeah
    : : :
    : : : procedure salesdata; var count:integer;
    : : : begin
    : : :
    : : : reset(sales);
    : : : readln(sales ,Data[year, month]);
    : : : write ('Please enter the appropriate year for the sales data');
    : : : readln(useryear);
    : : : if (useryear<1995) or (useryear >2010) then
    : : : repeat
    : : : writeln('please choose a year between 1995 to 2010');
    : : : readln(useryear);
    : : : until (useryear>=1995) and (useryear <=2010);
    : : :
    : : : begin
    : : : count:=0;
    : : : rewrite(sales);
    : : : for month:= 1 to maxmonth do
    : : : begin
    : : :
    : : : count :=count+1;
    : : : writeln ('please enter in the Sales value for month ', count,' year ', useryear);
    : : : readln(sales, Data[year, month]);
    : : : writeln(sales, Data[year, month]);
    : : : writeln(sales);
    : : : end;
    : : : end;
    : : : Close(sales);
    : : : end;
    : : : that is my code but i cant seem to enter a sales figure, it just loops throught and i am unable to enter any values for the month, did i do something wrong?
    : : :
    : : :
    : : If you want to enter data from the keyboard, you need to call readln() without any file-variables in the parameters. This will force Pascal to use the standard input, which is the keyboard.
    : :
    :
    : sawi, but yeah i tryed what you told me to put just readln();
    : but pascal is asking for a variable, i dunno what to do
    : i put it in
    :
    : writeln ('please enter in the Sales value for month ', count,' year ', useryear);
    : : : readln;
    : : : writeln(sales, Data[year, month]);
    : : : writeln(sales);
    : : : end;
    :
    :
    :
    Simply use:
    [code]
    Readln(Data[year, month]);
    [/code]
    This will allow the user to enter the value a single element in the array.
  • [b][red]This message was edited by joiboi at 2004-7-20 16:49:0[/red][/b][hr]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories