How can I tackle these challenging C programming tasks?
Asked by
9pt_serif
I'm a first-year university student currently learning programming in C, and I've hit a snag with a couple of tasks that seem quite daunting. Here's a breakdown of what I need to do:
**Task 7:** Create an array that can store:
1. 55 integers
2. 35 floating-point numbers
3. The string "This is my first string in the array"
4. The letters of the alphabet (excluding Polish characters)
5. A 16-bit binary number
6. Answers for a test labeled a, b, c, d
**Task 8:** Create an array that can store:
1. Students' last names
2. Consecutive prime numbers up to 100
3. 3D coordinates of a point
4. Battleship game boards suitable for placing three three-masted and three two-masted ships
5. Minesweeper game positions (1 for mines, 0 for no mines)
The issue is that the presentations we received didn't cover how to make arrays with multiple data types, and my searches online mostly tell me that this is "impossible." I'm unsure if I'm expected to create different arrays since the previous task involved displaying employee data from defined arrays. Any advice on how I should approach these tasks?
Answers
Itโs generally not feasible to mix data types in an array directly in C. For your tasks, it sounds like creating separate arrays would be the best approach. For example, youโd have one array for integers, another for floats, and so on, instead of trying to put everything in a single array.
Reply to this answer
You can't have arrays with mixed data types in C, so you're probably looking at multiple individual arrays or an array of structs. Task 6 showed you how to store different types of data within structs, so it might be useful for your later tasks too.
ApertureFan: I havenโt learned about structs yet! But I see them in my upcoming materials. I hope the tasks donโt require knowledge I havenโt been taught yet.
Reply to this answer
If this is really early in your C course, just thing about making distinct arrays for each item. Itโs what I would suggest to keep things simple. Building skills gradually is the key!
Reply to this answer
It sounds like Task 7 is asking you to create several separate arrays for each different type of data. Itโs common in C programming to not directly combine different data types in one array, so that might be what they expect. You could confirm this with your professor or TA to make sure you're on the right track.
+careful on the stairs!: Definitely ask for clarification! You might also say something like, 'I believe each of these items needs its own array,' to show your thought process.
Reply to this answer
You can look into arrays of structs, which might help you manage your data better if you eventually learn about them. Just donโt worry too muchโyouโve got this!
Reply to this answer
Add your answer
Answers are reviewed before publication.
foil_Au8: With structs being introduced later, this does feel too challenging for a first-year task!