smart parking system coding help needed

shubhamjain28:
yup changed it to 8 and i didnt get what you asked me to do in #1

Imagine you have an array with 5 boolean that can be either true or false

const boolean parkingIsAvailable[] = {false, true, true, false, false};

Exercise 1: Write a program which goes through the array and prints the index of only the entries which are true, one per line. Do all this in setup(), keep loop() empty. for the array above your console output should look like this (remember array index starts at 0)

[sub][color=blue]
Available Parking at index:
1
2
[/color][/sub]

Exercise 2: now put the answer on only one line: improve the previous code by adding punctuation => a comma needs to be printed to separate the true indexes - bring careful you don’t want a comma at the end of the list. Do all this in setup(), keep loop() empty

For the array above your console output should look like this (remember array index starts at 0)

[sub][color=blue]
Available Parking at index: 1, 2
[/color][/sub]

try by changing the array to

const boolean parkingIsAvailable[] = {false, true, true, false, true};

and

const boolean parkingIsAvailable[] = {true, false, true, false, true};

for example to ensure all works fine

Exercise 3: change the code from exercise 2 to improve a bit more because human don't usually count from 0 like computers but from 1 and add a letter in front of the digit, so array index 0 should appear as P1 the output to look like this (for the first array above)

[sub][color=blue]
Available Parking: P2, P3
[/color][/sub]

Exercise 4: change the code from exercise 3 to dynamically build the array from your sensors (so array can’t be const anymore). Add a function taking a trigger pin and sensor pin as parameter, returning a boolean. fill up the array in setup(), keep loop() empty

Exercise 5: make this now the real thing, so that it keeps looking Every 5 seconds to the status of the parking and print out the results