#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# How to code for a poll

Posts: 1

Greetings,
I have little code experience. I am in aviation and would like to make an app that by answering 10-20 multiple choice questions the app assigns a numerical value of risk to you. Example would be if you chose "A" you would get 4 points and at the end the app adds them together to give you your score. If you are less then 15 points you are low risk.

I'd appreciate any help or pointers on how to get started. Thank you

Casey

• Posts: 814

I don't have currently codes. But I'll try to explain. First try to programm some easy apps, later big projects.

• Mod
edited October 2016 Posts: 7,558

@helicase Here's something I just threw together that might get you started. Just fill in your questions, the answers, and the values you want for each answer.

EDIT: Tap on an answer for the next question. The values you assign to an answer will be added to the score.

``````function setup()
questions()
values()
score=0
quest=1
end

function draw()
background(40, 40, 50)
fill(255)
if quest<=#qTab then
text(qTab[quest],200,700)
text(aTab[quest][1],200,500)
text(aTab[quest][2],200,400)
text(aTab[quest][3],200,300)
text(aTab[quest][4],200,200)
else
text("No more questions",WIDTH/2,HEIGHT/2)
end
text("SCORE  "..score,WIDTH/2,HEIGHT-50)
end

function questions()
qTab={}
table.insert(qTab,"This is question 1")
table.insert(qTab,"This is question 2")
table.insert(qTab,"This is question 3")
table.insert(qTab,"This is question 4")
table.insert(qTab,"This is question 5")
end

aTab={}
table.insert(aTab,{"ans1-1","ans1-2","ans1-3","ans1-4"})
table.insert(aTab,{"ans2-1","ans2-2","ans2-3","ans2-4"})
table.insert(aTab,{"ans3-1","ans3-2","ans3-3","ans3-4"})
table.insert(aTab,{"ans4-1","ans4-2","ans4-3","ans4-4"})
table.insert(aTab,{"ans5-1","ans5-2","ans5-3","ans5-4"})
end

function values()
sTab={}
table.insert(sTab,{4,3,2,1})
table.insert(sTab,{1,4,3,2})
table.insert(sTab,{3,2,1,4})
table.insert(sTab,{2,3,4,1})
table.insert(sTab,{2,4,3,1})
end

function touched(t)
if t.state==ENDED and quest<=#qTab then
if t.x>0 and t.x<WIDTH and t.y>450 and t.y<550 then
score=score+sTab[quest][1]
quest=quest+1
end
if t.x>0 and t.x<WIDTH and t.y>350 and t.y<450 then
score=score+sTab[quest][2]
quest=quest+1
end
if t.x>0 and t.x<WIDTH and t.y>250 and t.y<350 then
score=score+sTab[quest][3]
quest=quest+1
end
if t.x>0 and t.x<WIDTH and t.y>150 and t.y<250 then
score=score+sTab[quest][4]
quest=quest+1
end
end
end
``````
• Posts: 8

This is what im looking for but the touch hitboxes are insanely big and i end up hitting four options some how which gives me four points after clicking the first answer?

• Mod
Posts: 5,396

It is very easy to make the hit boxes smaller.

If you find this too hard, then I suggest you need to learn and practise some more, otherwise you will never finish the app. You do need reasonable programming skills.

If you want to make a survey without spending dozens of hours learning programming, I'm sure there are plenty of web pages offering what you want.

• Mod
Posts: 5,396

I see you have another thread with the same question, so I've closed this one. There's no need to ask the same question twice.

This discussion has been closed.