red=Color.new(255,0,0)
green=Color.new(0,255,0)

x=0
y=0
z=0

select1=red
select2=red
select3=red
select=1
oldpad = Controls.read()
while true do
screen:clear()
pad = Controls.read()
if pad:start() then
	dofile("./System/formula.lua")
	break;
end

screen:print(100,100,"Surface Area: " .. ((x*y)*2)+((z*y)*2) .. "    Volume: " .. x*y*z,green)
screen:print(100,120,"X: " .. x, select1)
screen:print(100,140,"Y: " .. y, select2)
screen:print(100,160,"Z: " .. z, select3)

if select==1 then
	select1=green
	else
	select1=red
end
if select==2 then
	select2=green
	else
	select2=red
end
if select==3 then
	select3=green
	else
	select3=red
end
if pad:left() and pad:left() ~= oldpad:left() and select==1 then
	x=x-1
end
if pad:right() and pad:right() ~= oldpad:right() and select==1 then
	x=x+1
end

if pad:left() and pad:left() ~= oldpad:left() and select==2 then
	y=y-1
end
if pad:right() and pad:right() ~= oldpad:right() and select==2 then
	y=y+1
end

if pad:left() and pad:left() ~= oldpad:left() and select==3 then
	z=z-1
end
if pad:right() and pad:right() ~= oldpad:right() and select==3 then
	z=z+1
end

if pad:up() and pad:up() ~= oldpad:up() then
	select=select-1
end
if pad:down() and pad:down() ~= oldpad:down() then
	select=select+1
end

if select>3 then
	select=1
end
if select<1 then
	select=3
end
screen.waitVblankStart()
screen.flip()
oldpad=pad
end