Domanda

I have a software that asks user to choose different options from 3 sets of parameters before running the program with those inputs. However, I don't know how to show that in an algorithm or a Pseudo code in a correct way. Example

step 1: for X, choose from 5-10-15-20 
step 2: for Y, choose between a,b,c,d
step 3: for Z, choose from 10 to 20
step 4: calculate M=X+2Z
step 5: print row M of Y

Thanx for the help in advance

È stato utile?

Soluzione

There are no 'correct' ways in pseudo-code. You can really just do whatever you want, the only preference is that all terms and syntax used should be clearly understandable, thus, for syntax, it should be commonly used elsewhere to indicate the desired operation.

One option comes to mind: "Let X = a user-picked value from one of these: 5, 10, 15"

More brief: "Let the user pick X ∈ {5, 10, 15}"

Obviously if your algorithm fundamentally includes getting input from the user, this is not possible, but if the user input can be separated from your algorithm without changing anything, I would think a better way would be to say the value is given:

"Given X ∈ {5, 10, 15}"

It would make sense to me that all "Given"'s should be at the start of the algorithm. If you want to get something from the user in the middle of an algorithm, saying "Let the user pick..." as above would make more sense.

"In algorithms" doesn't really make sense. One can describe an algorithm in natural language (words / sentences / paragraphs), pseudo-code or in code in a specific language. And usually the user input is outside of the algorithm. For example, one would not say to get a list of values from the user for a sorting algorithm, one would start with "Given a list of values".

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top