How to Find Percentage of a Quiz On Processing

Hi. I am making a quiz using processing. Our teacher instructed us to create the function findPercent, which will find the percent of the quiz using the variable totalCorrect (represents the answers the user got correct on the quiz) and the total number of questions. Since the teacher is away and very busy, I have no clue what to do.[
[https://editor.p5js.org/seerhallow12247/sketches/x7a5hTh5P]

boolean findPercent(){
divide =totalCorrect/numberOfquestions;
percent = ((float)divide);

}
Sorry if I messed up on the formatting, I am very new to Processing.
Thanks

The part of the code with the boolean is the part of the code I am having trouble with. Sorry if I have been confusing.

When the function should return a float or integer number (percentage) then return type is float or int. In your case float.

Now the variable type before the function name is the return type. This is often

  • void (this function doesn’t return anything, like void draw() for example) or
  • here boolean (which returns a boolean, example would be: boolean isTheMouseOverMyButton() { ).

The function findPercent()

So in the line boolean findPercent() {

  • the function name is findPercent
  • the return type is boolean (which is not correct)

So replace boolean with float or int please.

Remark

And at the end of the function write
return percent;

Chrisir

2 Likes

When I tried to put float or int , it said unexpected token. What should I do now?

oops

did i see this wrong?

you link to the p5.js online editor,
with your sketch ( same user name )
but the code is JAVA.

-a- where that code come from? your teacher? in form of a file?
you make that account on p5.js and pasted that code?

-b- you want learn processing?


the error when you try to run the code

SyntaxError: unexpected token: identifier (sketch: line 1)

because already the first line is wrong ( language )

sorry that you lost 4 days ? for doing your homework?
but somehow that mistake slipped even 34 views on this topic??