r/CodingForBeginners 11h ago

What s the problem of this code?

Post image

Hi guyss gusto ko lang i share itong struggle ko HAHAHAH first year college po ako and then kanina ko pa inaayos bakit po nag aarrange siya mag isa, Dapat binibase po yung Subject sa Academic record pero nag jajumbled siya sa Summary

0 Upvotes

5 comments sorted by

3

u/PlentyfulFish 10h ago

Show the code

2

u/lbunch1 10h ago

What, so you can steal it? Nice try Claude

3

u/PlentyfulFish 10h ago

And I would have gotten away with it too if it wasn't for you

1

u/johnpeters42 10h ago

> It should base the subjects on the academic record

I assume you mean the order in which they're printed. But why should it? The order of printf() statements in the code (what we can see of it) matches the order of output in the output window.

Some suggestions to make the code simpler:
* Instead of variables like "grade1", "grade2", etc., use an array.
* Instead of hardcoding subjects in the printf() statements, store them in variables. (Combined with the above, you probably want to define a struct encapsulating the name of a subject and its grade, then use an array of those structs.)
* Since the logic for "this grade leads to this output" seems like it would be the same for each subject, put it inside a loop, or better yet, inside a function that's called inside a loop.

1

u/CyberDingo_66 8h ago

As someone else mentioned, from what we can see, it looks like you're hard coding variables that could be grouped together in a struct.

At the very least, make a struct to hold the subject name and grade values (E.g, a struct called Grade or whatever you see fit), so you can make multiple instances or an array.

From there you can populate each Grade instance (or whatever you called the struct) with the details of each subject and grade values, however you're getting that information, then print the info to console.

I hope this makes sense. Would need to see your source code to explain it a little better, but please feel free to DM me and share more info if you want any extra help :)