# When to use variables in C++

**URL:** <https://forum.codewithmosh.com/t/when-to-use-variables-in-c/22042>\
**Category:** C++\
**Created:** [August 15, 2023, 10:01pm UTC](https://forum.codewithmosh.com/t/when-to-use-variables-in-c/22042 "2023-08-15T22:01:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jahames](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Jahames](https://forum.codewithmosh.com/u/Jahames)\
**Post date:** [August 15, 2023, 10:01pm UTC](https://forum.codewithmosh.com/t/when-to-use-variables-in-c/22042/1 "2023-08-15T22:01:08Z")

</div>

I was doing a lesson in the C++ course and during one of the exercises I had used an integer to compare with the users input but when I watched the solution Mosh had used a variable instead which made me wonder, when is it better practice to use a variable and when is it better practice to just use a plain number. Thanks lads.

---

<div class="post-metadata">

**Author:** ![gulshan212](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/gulshan212/32/6217_2.png) [@gulshan212](https://forum.codewithmosh.com/u/gulshan212)\
**Post date:** [August 17, 2023, 3:06pm UTC](https://forum.codewithmosh.com/t/when-to-use-variables-in-c/22042/2 "2023-08-17T15:06:51Z")

</div>

Well, I searched about it on internet and I found that when you don’t need to convey additional context then you can use plain numbers, similarly when you have to change value multiple time within space then you have to use variable in C++.  
Thanks

---

<div class="post-metadata">

**Author:** ![Jahames](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Jahames](https://forum.codewithmosh.com/u/Jahames)\
**Post date:** [August 21, 2023, 1:50pm UTC](https://forum.codewithmosh.com/t/when-to-use-variables-in-c/22042/3 "2023-08-21T13:50:04Z")

</div>

Alright, that makes pretty good but sense, I didn’t want to be overusing variables and making my scripts unintelligible. Thanks mate, have a good one. 👍
