How can I tackle these challenging C programming tasks?

0
3
Asked By CharmingDolphin42 On

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?

5 Answers

Answered By SunnySideUp48 On

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!

Answered By PixelatedTurtle87 On

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.

CuriousCat3 -

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.

Answered By WanderlustTurtle56 On

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!

Answered By TechieGiraffe99 On

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.

ConfusedPanda88 -

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.

Answered By MysticLynx21 On

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.

EagerBee77 -

With structs being introduced later, this does feel too challenging for a first-year task!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.