I'm writing some code to calculate GPA and when I start a loop, one of my variables "numClasses" changes value to a huge number midway through the loop and I can't figure out what's going on.
#include <stdio.h> int main() { float crdtHrs[] = {}; //Credit hours for this term float numClasses; //Amount of classes taken this term float qltyPoints[] = {}; //Quality points for term float classes[] = {}; //Array for class grades printf("Please enter total number of classes -> "); scanf("%f", &numClasses); float a = numClasses; //using new variable because this way the loop works for(int i = 1; i <= a; i++) { printf("\nGPA class #%d -> ", i); scanf("%f", &classes[i - 1]); printf("Credit hours for course -> "); scanf("%f", &crdtHrs[i - 1]); printf("%f", numClasses); //at some point of my loop numClasses changes value } return(0); }
https://stackoverflow.com/questions/66021087/variable-changes-midway-through-loop-and-i-cant-figure-out-whats-the-problem February 03, 2021 at 12:01PM
没有评论:
发表评论