Page 1 of 1

Max

Posted: Tue Mar 25, 2014 8:48 pm
by Azulamanar
Hi,
How do you refer to a series of numbers in a string and find the max like the example below?
if ratings >=1 and ratings <=3 then put "poor" & "(" & ratings & ")" into rate
if ratings >=4 and ratings <=6 then put "good" & "(" & ratings & ")" into rate
if ratings >=7 and ratings <=10 then put "excellent" & "(" & ratings & ")" into rate
put rate into field "ratings"

So assuming rating was 1, 2, 3, 4 and 5. How do you refer to the highest with the max function?

Thanks

Re: Max

Posted: Tue Mar 25, 2014 9:00 pm
by dunbarx
Hi.

The code snippet you gave looks like it belongs in a "switch" construction.

How would you map those five numbers to the three ranges you gave? In other words, the ranges were:

1-3 inclusive (>=1 and ratings <=3)
4-6 inclusive
7-10 inclusive

But this is three cases with five choices. And I do not see the mapping since it looks like the third case is never reached. Whatever it is, though, the problem is easily solved. Is the variable "ratings" the same as what you said in the last line, talking about "rating"? Write back...

Craig Newman

Re: Max

Posted: Tue Mar 25, 2014 9:05 pm
by Azulamanar
Yeah, it starts like this.
It asks for a number between 1 to 10, then put it into ratings.

Re: Max

Posted: Tue Mar 25, 2014 11:54 pm
by dunbarx
OK.

What is your question, then? How to form a nice "switch" construction? How to map the values to the "poor, good excellent" categories? What did you want to know about the "max" function?

It looks like you already have it. Write back.

Craig

Re: Max

Posted: Wed Mar 26, 2014 12:04 am
by Azulamanar
Something like that but the rating list will be a series of numbers as it will be used for questionnaires. My question is how to use the max and min function to filter and display the highest and lowest ratings.

Re: Max

Posted: Wed Mar 26, 2014 4:18 am
by dunbarx
I guess I will need some sort of example to understand what you want.

Have you read in the dictionary about (and experimented with) these functions? They are simple to use. Making a selection from a list of numbers, based on some other criteria, is also straightforward, but I still do not quite get it. Did you mean what you said about referring to a string of numbers? What does this mean? Post a scenario in a stepwise fashion.

Craig

Re: Max

Posted: Wed Mar 26, 2014 7:37 am
by Azulamanar
The question from the task says:
1. Find and display the largest ratings
2. Calculate and display the number of questionnaires rated poor/good/excellent.

Ratings will be generated as illustrated in my first reply, it will be generated with the code and a loop. Therefore, ratings can be more than a number that is a series of number.
1. Question 1 was my initial question, that is referring to the highest number of ratings and displaying it. I only assume I am going to use max. and min. functions to find the highest and lowest ratings. The answer will be in this format: The highest rating tonight was: 6



Also, With the code if the ratings were: 3 (poor), 7 (excellent), 5 (good) and so on. Assuming there was around 100 ratings, How can I refer to them and say...
The customers rated tonight's service as: Poor : 24, good : 23 etc. This will refer to the 100 ratings.

Re: Max

Posted: Wed Mar 26, 2014 2:58 pm
by dunbarx
Hi.

It sounds like you need to practice a little with some basic techniques. For example, if you have ratings reported:

3,5,7,9,1,2,4,6,8,4,2,3,5,7,9,1,2,4,6,8,4,2

How can you sort these into your three groups so that you can count the number of instances in each group? This really calls for an array, but perhaps that is for the future. What if we sort these by item:

sort items of yourList (read up on the "sort" command in the dictionary) This would give you: 1,1,2,2,2,2,3,3,4,4,4,4,5,5,6,6,7,7,8,8,9,9

Does that give you a hint using the "itemOffset" function?

Or can you write a repeat loop that sorts the items into the three groups? You sort of did this already with your very first post. Can you set up a counter in each case so that as you loop through the items, you increment the counter for each group?

if ratings >=1 and ratings <=3 then
put "poor" & "(" & ratings & ")" into rate
add 1 to poorCount
...

We cannot write your application for you. We will answer all your questions forever. Try to work through your task in separate work modules. Ask questions in each module. If you really get stuck, and it is clear you are working hard, you may get a few complete handlers.

Craig

Re: Max

Posted: Wed Mar 26, 2014 3:31 pm
by dunbarx
Aw, hell. You are working hard.

Make a field. put a bunch of numbers in it separated by commas. Make a button with this in its script:

Code: Select all

on mouseUp
   get fld 1
   put 0 into poorCount
   put 0 into goodCount
      put 0 into excellentCount
   
   repeat for each item tItem in it
      if tItem >= 1 and tItem <= 3 then add 1 to poorCount
      else if tItem >= 4 and tItem <= 6 then add 1 to goodCount
      else add 1 to excellentCount
   end repeat
end mouseUp
Can you write this as a "switch" construction? Now you have the counts for each category. I hope you can extract the data in those three variables. What is the next thing?

Craig

Re: Max

Posted: Wed Mar 26, 2014 8:23 pm
by Azulamanar
Oh, thanks a bunch! looks simplified now.