Hi, I’m trying to make a calculator app, and one of the things I want it to do is work the problems out, not just give the answer. Is it even possible for codea to do this, if so how?

Thanks

Hi, I’m trying to make a calculator app, and one of the things I want it to do is work the problems out, not just give the answer. Is it even possible for codea to do this, if so how?

Thanks

This is a bit too vague to understand what you really want your app to do.

Can you post an example of:

.1 what the question looks like?

.2 what the answer looks like?

Sorry, Basically its a calculator, but it shows you how the problem was worked out. So if I sad subtract 20 and 30, it will show the entire process of subtracting it.

Ok. Can you detail what is the ‘entire process’ you expect for computing 20-30? I really have no clue…

Sorry if that wasn’t clear enough, this is what I ment

Ha, now i understand!

You can certainly do this, looking exactly as the nice drawings.

But you have to code yourself all the details. So when you say ‘how?’, mmm… Maybe: ’ ask Dave1707’ would be the simplest solution for you…

@Prynok I was going to respond to your first post, but I had to go somewhere. I was going to ask exactly what @Jmv38 did. I looked at the example link you posted. Yes it’s doable, but it’s a lot of detail type of coding. I’ll see if I can give you an example as soon as I get some time to play around once I get the yard work done.

@Prynok Here is an over simplified hard coded example. I don’t know if you would want multiple problems, one after the other, but this is just a start to give you an idea.

```
displayMode(FULLSCREEN)
function setup()
sf={s1,s2,s3,s4,s5}
s=1
a={ "Problem, subtract one number from another",
"Subtract the left hand column of digits",
"Move left and subtract the next column of digits",
"Move left again and subtract that column",
"Giving the final answer"}
end
function draw()
background(40, 40, 50)
fill(255)
font("CourierNewPS-BoldItalicMT")
rectMode(CORNER)
stroke(255)
strokeWidth(4)
fontSize(20)
text(a[s],350,500)
text("tap screen",300,200)
fontSize(50)
sf[s]()
end
function s1()
fill(255)
text(" 369",300,400)
text("-123",300,350)
text("----",300,325)
end
function s2()
noFill()
rect(330,280,35,150)
s1()
text(" 6",300,300)
end
function s3()
noFill()
rect(300,280,35,150)
s1()
text(" 46",300,300)
end
function s4()
noFill()
rect(270,280,35,150)
s1()
text(" 246",300,300)
end
function s5()
s1()
text(" 246",300,300)
end
function touched(t)
if t.state==BEGAN then
s=s+1
if s>5 then
s=1
end
end
end
```

Ok, thank you!

@Dave1707 Sorry if my post wasn’t clear enough, but I was wanting to know how to take away numbers, for example, if you can’t subtract 110 and 70

because 7 is bigger then one, so the program crosses out the one hundred, and carries it over to the ten

@Prynok Here’s an example of subtracting 70 from 110. The text may need to be worded better. This just shows that it’s possible to do something like the link you showed. More color can be added, the wording can be better, etc.

```
displayMode(FULLSCREEN)
function setup()
sf={s1,s2,s3,s4}
s=1
a={ "Problem, subtract one number from another",
"Subtract the left hand column of digits",
"Move left and subtract the next column of digits.\
Because you can't subtract 7 from 1, you have to \
borrow 10 from the digit to the right, subtracting \
1 from it",
"Move left again and subtract that column",
"Giving the final answer"}
end
function draw()
background(40, 40, 50)
fill(255)
font("CourierNewPS-BoldItalicMT")
rectMode(CORNER)
stroke(255)
strokeWidth(4)
fontSize(20)
text(a[s],350,550)
text("tap screen",300,200)
fontSize(50)
sf[s]()
end
function s1()
fill(255)
text(" 110",300,400)
text("- 70",300,350)
text("----",300,325)
end
function s2()
noFill()
rect(330,280,35,150)
s1()
text(" 0",300,300)
end
function s3()
noFill()
rect(300,280,35,150)
s1()
text(" 40",300,300)
text("//",300,400)
fontSize(16)
text("11",320,440)
text("0",290,440)
end
function s4()
text(" 110",300,400)
text("- 70",300,350)
text("----",300,325)
text(" 40",300,300)
text("//",300,400)
fontSize(16)
text("11",320,440)
text("0",290,440)
end
function touched(t)
if t.state==BEGAN then
s=s+1
if s>4 then
s=1
end
end
end
```

Great! But how do you change the numbers? Because the 110 subtracted from 70 was an example to prove a point, how could you, for say let the user type in numbers?

The way it’s written now, you can only change the numbers by totally changing the code. This would have to be re-written if the numbers were changed randomly or using the keyboard. It’s going to take a lot more code than I’m showing here. What I show in these examples is that it’s possible to display something like the link you posted. I’m not sure if you’ll want to take on that much coding for what looks like not that much in return.

I really want to, its just I’m not sure how to scan through numbers in two integers, and compare them

@Prynok Here’s one way to seperate a number into it’s individual digits.

```
function setup()
str={}
a=13579
split(a)
print(a)
for a,b in pairs(str) do
print(b)
end
end
function split(val)
while val>0 do
table.insert(str,val%10)
val=math.floor(val/10)
end
end
```

Maybe to get the individual numbers you can use `tostring()`

on the numbers, and then use `string.sub()`

on it?

Pseudo-code:

```
local numstr = tostring(num)
local numstr2 = tostring(num2)
for i = 1, math.max(string.len(numstr), string.len(numstr2)) do
local c = string.sub(numstr, i, i)
local c2 = string.sub(numstr2, i, i)
-- Compare c and c2.
end
```

One set of numbers would be in one table, the other number in another table. You would then compare the digits using their table offset. For instance, str1[1] compared to str2[1].