What is wrong with the following code? float scores[10], total; nothing Cannot declare regular and array variables together. The 10 should be replaced with a variable name, whose value is input from the user. Arrays must be integers.
Solución de tutoría real
Responder
Solución
¡Inicia sesión para desbloquear respuestas gratis!
Una plataforma de aprendizaje en la que confían millones de estudiantes y profesores reales.
Revisado y aprobado por el equipo de tutoría de UpStudy
The Deep Dive
The code snippets you’ve provided seem to be raising a few eyebrows! First off, the declaration of `float scores[10]` is perfectly valid in C (and similar languages) as arrays can indeed have a fixed size defined by a constant integer, and the type can be a float. However, if you're aiming for a more dynamic approach, you're right to consider using a variable instead of a fixed size. For example, if you want to let the user specify the number of scores, you'll need dynamic memory allocation methods such as `malloc`. This makes your program adaptable, and you won't be stuck with just 10 scores! In the end, ensure the right data types are used and the sizes defined correctly - and your code will sail smoothly!