program with arrays: y=ln(x)

Hey,
 Wondered if anyone might have any idea how to do this program, been giving me a bit of hassle. Thanks a million!
 
 y=loge(x), i need to write a program which will display a table of logs for varying values of x. Theuser should be instructed to enter the minimum value of x, the maximum value and the size of increment between these values. The program should then use one procedure to calculate thevalues of x and store them in an array and another procedure to calculate the corresponding values of y (also in an array).
e.g.. the user has entered xmin = 0.1, xmax = 1.0, xincrement = 0.05
The x array will therefore have the values :
0.10, 0.15, 0.20, …. Which will fill the x array.
And the y array will therefore have the values :
-2,30, -1.89, -1.61, …. Which will fill the y array.
You will have to make sure the user can't ask for more points than are contained in the array.
For example, if you define your arrays to have 50 elements and the user needs 100 points
between xmin and xmax then you must stop and warn the user that they have asked for too many
points and ask them to try again..
eimearneesonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WelkinMazeCommented:
Hi,
This looks like a homework so you have to post the code of what you've done so far and we can help you then if there are some mistakes.
0
eimearneesonAuthor Commented:
yeah, so far

PROGRAM ln_example;

VAR
  list     : ARRAY [0..100] OF integer;
  loge   : ARRAY[ARRAY[0..10] OF integer OF O..100;
  num   : integer;
  inc     : integer;
  numz : integer;

BEGIN

   begin
      num := num + inc;
      IF num > 0 AND num <= numz DO
      list (ARRAY[num]);
  end;

   begin
     loge  := ln(lit(num));
   end;

   writeln('Please enter minimum x value: ':2);
   readln(num);
   writeln('Please enter maximum x value: ':2);
   readln(numz);
   writeln('Please enter size of increment: ':2);
   readln(inc);
   writeln(loge[num]);

END.

if you could point out what ive done wrong, that would be amazing. thanks.
0
WelkinMazeCommented:
loge   : ARRAY[ARRAY[0..10] OF integer OF O..100;
what is the idea of this one?
what is ARRAY[ARRAY
also in O..100 I suppose it has to be 0 (zero) not O (the letter O)
0
mlmccCommented:
YOu will want to use parallel arrays.  By that I mean the arrays have the same shape and indices.

Since your list is 1 - 100 then your array for the loge must also be 1 - 100.  Same basic declaration.

Have you learned about user defined data types?  Have you learned about functions and procedures?

THink about how you would do this manually

Step 1 - Ask user how many values, minimum value, and increment
Step 2 - Validate values - what values for each would be invalid - (More than your program allows, negative minimum value, etc)
     Repat step 1 & 2 for each invalid value
Step 3 -

mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
For-SoftCommented:
VAR
  list     : ARRAY [0..100] OF integer;
  loge   : ARRAY[ARRAY[0..10] OF integer OF O..100;
  num   : integer;
  inc     : integer;
  numz : integer;

As an example you used real type values. It is not possible to store such values in variables you declared. The variables have to be real type to work correctly in such a case:

const SizeOfArray = 100;

VAR
  list     : ARRAY [0..SizeOfArray] OF Real;
  loge   : ARRAY [0..SizeOfArray] OF Real;
  num   : Real;
  inc     : Real;
  numz : Real;

The SizeOfArray constant is just to make changing of the array size more easy. But it shows the both arrays have to be the same size. It is possible to declare 1 variable instead of two. But, you told us you have to create two separate tables. So, I'll leave it, for now.

The rest of your program should follow the steps, just like Mlmcc said. The validation of the values should be done in some sort of a loop. Repeat .. Until is a possible solution:

BEGIN

 repeat
 
 {STEP 1 - Ask user how many values, minimum value, and increment}
   writeln('Please enter minimum x value: ':2);
   readln(num);
   writeln('Please enter maximum x value: ':2);
   readln(numz);
   writeln('Please enter size of increment: ':2);
   readln(inc);
   writeln(loge[num]);

 {Step 2 - Validate values}
 until (validation expression goes here)

 {Step 3 - }

END.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.