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

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 19

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

    #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

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

    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 Рік тому +3

      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 11 місяців тому

      The same sitution Bro

    • @BroDevsRBLX
      @BroDevsRBLX 11 місяців тому

      @@crogat2298 goddamn bro. Whole motivational speech🤣

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

    Good Video. Let's defeat the YT algorithm.

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

    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 5 місяців тому +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 Місяць тому

      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.

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

    Nice

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

    what do you mean 5 is small??

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

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

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

      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

  • @WaaABwvoGkiiCNXFQUnlMroDVoMmqy

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

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

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

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

      definitely do you have a discord

  • @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