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]
Sorry for the late answer. I had no idea that the type of code that was supposed to be put in p5.js was not JAVA. My teacher wrote the first line as part of the example code. Here’s the line: String myText ;
`
int numOfQuestionsTotal = 12; // number Of Questions in Total (e.g. 12)
int totalCorrect = 4; // number of correct answers (e.g. 9)
void setup() {
size(300, 300);
background(0);
float percent = findPercent( totalCorrect, numOfQuestionsTotal) ;
println(percent + " %");
}
void draw() {
//
}
// ----------------------------------------------------------------------------------
float findPercent( int currentValue, int BaseValue ) {
// The percent value is computed by multiplying the numeric value of the ratio by 100.
// https://en.wikipedia.org/wiki/Percentage#Calculations
float ratio = (float) currentValue / (float) BaseValue;
float percent = ratio * 100.0;
return percent;
}
//
Sorry, but I didn’t make it clear that the percentage is calculated based on user input, not based on preprogrammed numbers. These variables: int totalCorrect = 0; int totalWrong = 0;
have to start at 0.