Solved

# program with arrays: y=ln(x)

Posted on 2006-04-24
337 Views
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..
0
Question by:eimearneeson

LVL 11

Expert Comment

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

Author Comment

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);
writeln('Please enter maximum x value: ':2);
writeln('Please enter size of increment: ':2);
writeln(loge[num]);

END.

if you could point out what ive done wrong, that would be amazing. thanks.
0

LVL 11

Expert Comment

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

LVL 100

Accepted Solution

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

LVL 10

Assisted Solution

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);
writeln('Please enter maximum x value: ':2);
writeln('Please enter size of increment: ':2);
writeln(loge[num]);

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

{Step 3 - }

END.
0

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

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

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

#### Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!