how to compare two integers

how to compare two integers

  

Hi,

I have an aggregate which is containing Question, Passenger, Answer Entities and I want to check whether the ans for the particular question is given by the passenger is correct or not and for that I have made One additional attribute CheckAnswer and given the value as 1(for one category of questions) because I have Questions in Yes or No pattern with the values as 1 and 2 respectively.

But I am unable to compare the ans given by all the passengers because I have to use foreach loop but I am not getting which connector should we use where?

I have ans in IsAnswer attribute(Ans given by each passenger) and Expected ans in CheckAnswer attribute (the ans which should be given by each passenger).

I am not able to compare the given ans with the expected ans for each passenger.

Please help me with this asap.


Hi,

I don't know if I understood what you want. But if you want compare IsAnswer with CheckAnsewer you can create a new column with as a result of If((IsAnswer - CheckAnswer) = 0,"equal","not equal" ).

Please let me know if this is the solution what you want.

Hi Ankita,

First, a couple of observations. For one, please type "answer" when you mean "answer", instead of "ans". It seems you're proficient enough in English, so use English. Secondly, naming: you have an Attribute called "IsAnswer", but it isn't a Boolean but an Integer. This is bad design: the Platform will automatically assign the type of Boolean to Variables and Attributes that start with "Is", and it's a common practice in other programming languages as well, so everyone reading your code will assume it's a Boolean. If you can still change it, do so. More or less the same goes for "CheckAnswer" - if this is the right answer, why not name it just "Answer" (and "IsAnswer" to "AnswerGive" or the like)?

Then, onto your question. As Diogo already implied, it's not quite clear what you want to do. If you want to have a Boolean for each row that indicates whether the answer given is equal to the right answer, you can add a New Attribute (by clicking "New attribute" in the Aggregate), and set it's Value (a.k.a. Formula) to "IsAnswer = CheckAnswer". This will result in a Boolean that tells you whether the answer is correct or not.

@Diogo: why on earth would you compare to values by subtracting them and then comparing them to 0? What's wrong with just "IsAnswer = CheckAnswer"?

Kilian Hekhuis wrote:

Hi Ankita,

First, a couple of observations. For one, please type "answer" when you mean "answer", instead of "ans". It seems you're proficient enough in English, so use English. Secondly, naming: you have an Attribute called "IsAnswer", but it isn't a Boolean but an Integer. This is bad design: the Platform will automatically assign the type of Boolean to Variables and Attributes that start with "Is", and it's a common practice in other programming languages as well, so everyone reading your code will assume it's a Boolean. If you can still change it, do so. More or less the same goes for "CheckAnswer" - if this is the right answer, why not name it just "Answer" (and "IsAnswer" to "AnswerGive" or the like)?

Then, onto your question. As Diogo already implied, it's not quite clear what you want to do. If you want to have a Boolean for each row that indicates whether the answer given is equal to the right answer, you can add a New Attribute (by clicking "New attribute" in the Aggregate), and set it's Value (a.k.a. Formula) to "IsAnswer = CheckAnswer". This will result in a Boolean that tells you whether the answer is correct or not.

@Diogo: why on earth would you compare to values by subtracting them and then comparing them to 0? What's wrong with just "IsAnswer = CheckAnswer"?


Hi Kilian, 

Yes. "IsAnswer = CheckAnswer" is right right way... My bad

Diogo Coelho wrote:

Kilian Hekhuis wrote:

Hi Ankita,

First, a couple of observations. For one, please type "answer" when you mean "answer", instead of "ans". It seems you're proficient enough in English, so use English. Secondly, naming: you have an Attribute called "IsAnswer", but it isn't a Boolean but an Integer. This is bad design: the Platform will automatically assign the type of Boolean to Variables and Attributes that start with "Is", and it's a common practice in other programming languages as well, so everyone reading your code will assume it's a Boolean. If you can still change it, do so. More or less the same goes for "CheckAnswer" - if this is the right answer, why not name it just "Answer" (and "IsAnswer" to "AnswerGive" or the like)?

Then, onto your question. As Diogo already implied, it's not quite clear what you want to do. If you want to have a Boolean for each row that indicates whether the answer given is equal to the right answer, you can add a New Attribute (by clicking "New attribute" in the Aggregate), and set it's Value (a.k.a. Formula) to "IsAnswer = CheckAnswer". This will result in a Boolean that tells you whether the answer is correct or not.

@Diogo: why on earth would you compare to values by subtracting them and then comparing them to 0? What's wrong with just "IsAnswer = CheckAnswer"?


Hi Kilian, 

Yes. "IsAnswer = CheckAnswer" is right right way... My bad

I have used this but not able to compare the given questions.

The correct feedback I am not getting.


Hi Ankita,

What do you mean you're "not able to compare the given questions"? What kind of "correct feedback" are you expecting?

Yes, please give more detail. What happening? Do you can show the if in new column?