# Why won't this random generated question desmos count correct answers?

I am creating a simple and compound interest practice that generates random numbers for the questions. I would like the count of correct answers to be tallied after each question is answered. Because it is money, I have included code that requires the answer to be rounded to 2 decimal places to be counted correct. Something is not jiving with the way it is counting correct answers though… help please!

I’d also like for the rate to be randomly generated rational decimal numbers with up to 2 decimals instead of positive integers only. Any help on that end would be greatly appreciate as well!

Thanks so much!

Simple and Compound Interest Practice

Everything you’ve put already works, other than you have `roundedAnswer` being dependent on A1.submitted for some reason. So at the point you submit your answer, technically `this.latex` cannot equal `roundedAnswer` because `roundedAnswer` is just “” at that point. If you remove that dependency, it works absolutely fine.

Given that you have a hidden graph component tracking the scores, I would move all of the calculations and random generation stuff into that graph - it’s much easier to do calculations there and then call them using `G1.number('...')`.

To address your final point, if you use `P=round(random()*10,2)` in the graph, this will give you a randomly generated number between 0 and 10 with two decimal places. Then call it in the CL using `G1.number('P')` wherever you need it.

Thank you very much - removing the dependency did work!

However, the code:

r=round(random()*10,2) did not work

Just confirming that you put that expression in the graph component, not the CL?

ahh - no I did not. I’ll try that and get back!

So doing this does not create a new random number every time the new problem button is pressed?

So that’s because the `random()` hasn’t been seeded.

To get it to update, you would need to replace with `P=round(random(1,s)*10,2)[1]`, and in the CL for the graph include `number('s'): B1.pressCount`

The `random(1,s)` basically means “create a random list of 1 number, using the seed s” - hence why we now need to tag [1] onto the end, so that it picks item 1 (from a list of 1).

If that’s too messy for you then you can actually generate a floating point random number in CL using `.float(1,10)` instead of `.int(1,10)`… but you’d have to round it to 2d.p. somehow too.