Arrays with If/then statements and fouts

Self Resolved problem.
Last edited on
char lettergrade [7]; //Shadows global
lettergrade [7]='F'; //Buffer overflow here: lettergrade contains 7 values with indexes [0;6] 
First advice: get rid of globals

float (progscore1[row]+progscore2[row]+progscore3[row])/(3);
Second advice: get rid of c-style casts. Unnecessary casts actually:
(progscore1[row] + progscore2[row] + progscore3[row]) / 3.0;
Last edited on
Neither of those variables are global though...and i'm confused? If I dont apply an array to lettergrade then it will give me an error "incompatible types in assignment of char to char [7]

I used a cast because I'm dividing integers but that will provide decimal places for my averages.
What do you think should happens when you assign one value to array of 7 values?
Either way, lettergrade is local to function and will be destroyed when function returns.
Last edited on
I'm sorry I've left our a crucial part. I'm inputting information from a text value...there are 7 students so there will be 7 values.
Last edited on
You didn't answer my question: "What do you think should happens when you assign one value to array of 7 values?"
You might want to iterate over array and assign each element of array its score.
Also you should consider use of structs to efficiently store student information and to stop getting lost in simle algorithms. Remember OOP, aggregate data and basically everything in language development was created to make code more readable and safe.
Last edited on
Topic archived. No new replies allowed.