# Simple Vector - UndefVar Error

**URL:** <https://discourse.julialang.org/t/simple-vector-undefvar-error/75419>\
**Category:** New to Julia\
**Tags:** question, vector, error-message\
**Created:** [January 29, 2022, 3:25pm UTC](https://discourse.julialang.org/t/simple-vector-undefvar-error/75419 "2022-01-29T15:25:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandras002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chandras002/32/707_2.png) [@chandras002](https://discourse.julialang.org/u/chandras002)\
**Post date:** [January 29, 2022, 3:25pm UTC](https://discourse.julialang.org/t/simple-vector-undefvar-error/75419/1 "2022-01-29T15:25:50Z")

</div>

I am trying to learn Vector implementation in Julia. (1.7.1)  
Following code gives : **Candidate not defined" error.**  
The code has taken from the question here.  
[Stack overflow](https://stackoverflow.com/questions/62550582/error-loaderror-boundserror-attempt-to-access-0-element-arraycandidate-1-a)

What is wrong here? what is the correct way?

```julia
const max_candidates = 9
candidates = Vector{Candidate}(undef, max_candidates)

for i in 1:max_candidates
 println("Name of the candidate: ?")
 name = readline();
 println("Votes on him: ?")
 votes = parse(Int, readline());
 candidates[i] = Candidate(name, votes)
 println("Thank you, let us move to the next candidate.")
end

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 29, 2022, 4:15pm UTC](https://discourse.julialang.org/t/simple-vector-undefvar-error/75419/2 "2022-01-29T16:15:13Z")

</div>

> [@chandras002](#):
>
> Following code gives : **Candidate not defined" error.**

Means exactly what it says: you hadn’t defined `Candidate` yet when you executed this code. It’s presumably supposed to be some kind of `struct`?

See [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![chandras002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chandras002/32/707_2.png) [@chandras002](https://discourse.julialang.org/u/chandras002)\
**Post date:** [January 31, 2022, 5:31am UTC](https://discourse.julialang.org/t/simple-vector-undefvar-error/75419/3 "2022-01-31T05:31:25Z")

</div>

yes, missed the struct part. Fixed it by declaring it. Thanks.

```julia
mutable struct Candidate
   name::String
   votes::Int8
end

```
