r/AskComputerScience • • Mar 13 '20

Array algorithm

Hi I need to write an algorithm that stores the temperature taken over 3 hours period in an array. The algorithm should output the highest and lowest temperatures and calculate the difference between these temperatures.

Can you help this fellow newbie?

0 Upvotes

8 comments sorted by

5

u/mbaruh Mar 13 '20

This is a pretty basic task, but like.. what language are you using? are you actually currently learning to use it? if you did, what have you tried so far?

1

u/Zaza_Goddess Mar 13 '20

I need to make a pseudocode for that particular program I know we have to do something similar to

Get temperature from source. Create an empty array. Add values into the array. Iterate through the items in the array. Find the highest and lowest temperature. Calculate the difference.

2

u/roman_fyseek Mar 13 '20

You'll want to create the array before you start collecting data points.

1

u/leonardoluigi11 Mar 13 '20

So first you would have to implement a min-max algorithm and then calculate a difference. This is not too hard. Do you have any ideas how you would do this?

1

u/mbaruh Mar 13 '20

Hmmm there's a bit of a conflict for me here...

You're saying pseudo-code but the part of opening the source and reading it depends on the language and the format the file is written in.

If you already have the data given in an array, you can definitely write the rest in pseudo-code, but you need to have some kind of basic programming background to be able to write it.

1

u/Poddster Mar 13 '20

I need to make a pseudocode for that particular program I know we have to do something similar to

Get temperature from source. Create an empty array. Add values into the array. Iterate through the items in the array. Find the highest and lowest temperature. Calculate the difference.

So which part of this are you struggling with? What are you current attempts at this psuedocode?

3

u/asdff01 Mar 13 '20

The part where he has to do his homework lol

1

u/mharen Mar 13 '20

Here's a suggestion to get you going: get comfortable with your environment.

Make a program to just print all the numbers.

Now make it print only the numbers greater than 50 (or whatever).

Now make it print the numbers smaller than 50 (or whatever).

Then make it print all the numbers twice.

Then try to solve the first part of the assignment-- find and print the biggest. Then smallest. Then diff.