Cpp code improvement | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Cpp code improvement

How can this code be improved? Just finished working on it: https://sololearn.com/compiler-playground/cDd5kN7rsC2Q/?ref=app

28th Feb 2024, 8:35 PM
Lamron
Lamron - avatar
9 Respuestas
+ 4
What I'm sure of is that you definitely can pack the repetitive inputs at the beginning into a loop iterating over the coins, making the prompt string be mentioned in the code only once. And you can really simplify this output case list section into just getting the index of unique message to display and right coin indexes to use inside it, then just composing the message at the end. This would make the code a lot shorter and cleaner.
28th Feb 2024, 11:44 PM
Tabs Morgan
Tabs Morgan - avatar
+ 3
what is the right weight? Also, the output does not make sense if all of the inputs are equal. I would probably put every input in an array to make getting the inputs simpler, then do a more generalised math operation to get the result rather than comparing manually.
29th Feb 2024, 12:56 AM
Bob_Li
Bob_Li - avatar
+ 3
Tell the user what the code is about and what to input in comments when you start your code even before the #include so he does not have to scroll all along the code and look for the cin tags
1st Mar 2024, 4:03 AM
Rana Saarrthi
Rana Saarrthi - avatar
+ 1
I would recommend improving variable names
28th Feb 2024, 8:51 PM
Junior
Junior - avatar
+ 1
That's the last thing I would look like. What I'm looking for is a better structure, approach.
28th Feb 2024, 9:01 PM
Lamron
Lamron - avatar
+ 1
So a better way to get the same output?
28th Feb 2024, 9:22 PM
Junior
Junior - avatar
+ 1
Thanks for guidance
1st Mar 2024, 7:23 AM
Lamron
Lamron - avatar
+ 1
i suggest to write it in a good manner so it will become readable
1st Mar 2024, 3:49 PM
Alhaaz
Alhaaz - avatar
0
Alhaaz, I suggest you practice giving constructive criticizm so it will become helpful
1st Mar 2024, 9:17 PM
Tabs Morgan
Tabs Morgan - avatar