C++ How to fill an array with user input 🌭

Поділитися
Вставка
  • Опубліковано 5 лют 2025
  • #C++ #input #array
    C++ enter user input into an array tutorial example explained

КОМЕНТАРІ • 22

  • @BroCodez
    @BroCodez  2 роки тому +13

    #include

    int main()
    {
    std::string foods[5];
    int size = sizeof(foods)/sizeof(foods[0]);
    std::string temp;
    for(int i = 0; i < size; i++){
    std::cout

  • @nguyenminhquang7052
    @nguyenminhquang7052 26 днів тому

    Only legends could have gone this far. Proud to be here

  • @rykuthebigryku
    @rykuthebigryku Рік тому +6

    hi,is it normal if i have difficulties understanding some of theses concepts?(this one wasn't hard but i've been having a hard time on these last videos i watched)

    • @BroDevsRBLX
      @BroDevsRBLX Рік тому

      I can help if your still stuck

    • @crogat2298
      @crogat2298 Рік тому +4

      It may be hard at first, but if you keep trying with programs using these concepts it'll eventually click. The main difference between someone who'll succeed learning to code and someone how willing you are to learn no matter how tough it gets.

    • @zai01123
      @zai01123 Рік тому

      The same sitution Bro

    • @BroDevsRBLX
      @BroDevsRBLX Рік тому

      @@crogat2298 goddamn bro. Whole motivational speech🤣

  • @lastwaveundergroundsaviour7037
    @lastwaveundergroundsaviour7037 2 роки тому +12

    So i'm pretty sure using !foods.empty in the for loop like that, will make it out of bounds when entering 5 elements. So I changed this, and i'm sure its better, nested inside the for loop add the !foods thing in a if statement. Like this.
    for(int i = 0; i < size; i++){
    if(!foods[i].empty()){
    std::cout

    • @Dazza_Doo
      @Dazza_Doo 2 роки тому +1

      Hmmm, it is a Logic condition, so I don't think you would have anything to worry about, Logic doesn't run out of bounds, as far as I know

  • @lanvirrusselacosta7870
    @lanvirrusselacosta7870 6 місяців тому +2

    Do we really have to make a new variable "food" to call out the input value? Can't we display the value thru cout and put the variable "foods" to display the input value?
    And why exactly we divide the getsize foods[5] to getsize foods [0] where as the second one has no value?

    • @virtually2124
      @virtually2124 3 місяці тому

      arrgh but getsize foods [0] does have a value of 5 (or what number you have in the line above), and sizeof(foods) has 5 times that or 120 in this case.

  • @MainulHossainAnik
    @MainulHossainAnik 5 днів тому +1

    🔥🔥❤❤DONE🔥🔥❤❤

  • @FrederikWollert
    @FrederikWollert 9 місяців тому +2

    Good Video. Let's defeat the YT algorithm.

  • @aaayme
    @aaayme Рік тому

    Nice

  • @virtually2124
    @virtually2124 3 місяці тому

    I get a "Segmentation error", but if I use 'q' before finishing the 5 foods the error does not show

    • @virtually2124
      @virtually2124 3 місяці тому

      Oh back again after doing something else, if I change the code to
      string foods[6];
      // int size = sizeof(foods)/sizeof(foods[0]);
      int size = (sizeof(foods)/sizeof(foods[0]))-1;
      it is alright and does not show Segmentation error

  • @wlsedlacek
    @wlsedlacek Рік тому +1

    what do you mean 5 is small??

  • @lauday68566z
    @lauday68566z Місяць тому

    hey bro can we use if (anime[i] == "q")
    {
    break;
    } this instead of !foods[i].empty()

  • @WaaABwvoGkiiCNXFQUnlMroDVoMmqy

    #include
    using namespace std;
    int main()
    {
    string foods[5];
    string temp;
    for (int i = 0; i < size(foods); i++)
    {
    cout

  • @Dazza_Doo
    @Dazza_Doo 2 роки тому +1

    for (int i = 0; !foods[i].empty(); i++) - I've never thought about doing this check before, expanding my Thinker

  • @zdofficial3740
    @zdofficial3740 9 місяців тому

    anyone willing to share their contact info .i am new to coding anyone new wanna help each other out anyone

    • @mikeykun5026
      @mikeykun5026 8 місяців тому +1

      definitely do you have a discord