Hello all,
I'm using an Arduino Uno R3. Software is Arduino 1.8.8
My project is a small program that can be used to average grades. The end goal is to learn more about arrays.
I followed a tutorial on youtube. That instructor (Paul McWhorter) used Arduino 1.6.8
The code ran properly for him. For me, once I input the number of grades I am then prompted to input a grade. Once I do the code spits out a grade average instead of prompting me for the remaining grades.
(ex. If I input 3 for "How many grades?" it should prompt me for all 3 grades then report the grade average to me.)
As you can see I noted all the {} in my code to be certain they were correct.
After searching many forums and googling the issue I can find no pertinent info on this problem.
I have tried changing "i" to 1 in my second 'for' statement along with different combinations of <,>,= to no avail.
The entire code is posted. Any suggestions will be most appreciated.
Thanks,
Tim
float grades[25]; //an array, it sets the number of grades
int numGrades; //creates a variable for the number of grades
float av; //a variable for grade averages
int i; //a variable to hold grades
float sumGrades=0; //a variable to add grades
void setup() {
Serial.begin(9600); //turn on serial printer
}
void loop() { //void loop begins
Serial.println("How many grades? "); //prompt used for input
while(Serial.available()==0){ //while there is no data we wait ---while loop 1 begins
} //while loop 1 ends
numGrades=Serial.parseInt(); //(use Serial.parseInt to read ints') - this line reads the # of grades input by the user
for(i=0; i<numGrades; i=i+1);{ //for loop 1 begins---this will loop until numGrades is reached.
Serial.println("Please input your grade: "); //prompt used for grades
while(Serial.available()==0){ //while loop 2 begins
} //while loop 2 ends
grades[i]=Serial.parseFloat(); //reads the grades
} //for loop 1 ends
for(i=0; i<=numGrades; i=i+1);{ //for loop 2 begins
sumGrades=sumGrades+grades[i];
} //for loop 2 ends
av=sumGrades/numGrades;
Serial.print("Your average is ");
Serial.println(av);
Serial.println("");
sumGrades=0;
} //void loop ends