The basics of programming in c++ for beginners

Tasks: while loops, do while, nested loops

We met with loops while and do while in C++ and c nested constructions in loops. Let us tasks solving.

1. Organize continuous input of numbers with the keyboard, until the user has entered 0. After entering a zero, show on the screen the number of numbers, which were introduced, their total amount and the arithmetic mean. Tip: you must declare the counter variable, that will count the number of entered numbers, and variable, that will accumulate a total sum of numbers.

2. It is necessary to sum up all the odd integers, which will introduce the user to the keyboard.

3. The task is more difficult. Draw an isosceles triangle of characters ^. The height of a user selects. For example: height = 5, on the screen

task nested loops

177 thoughts on “Tasks: while loops, do while, nested loops

      1. Prompt,you are welcome, where is the mistake, I can not understand what's wrong done, displays the result just 0

  1. Oh-a-lol . for the final solution of the problem it was not easy to understand , much less write.
    I had to brush up on something he did not know. I believe it is necessary in parallel with the programming should be studied as a subject of Logic. And know well the math.
    I continue to gnaw science.

  2. You task in an error in the code ____ for(int b=height-2*a; b++)) ____ should be so ______ for(int b;b=height-2*a; b++)________ if it gives your initialization error

    1. The example is written:

      for (int j = height - 2 * i; j <= height; j++)

      And this correctly!
      And the fact that you have written, – this is bullshit: here you have declared not initialized cycle variable b, with undetermined,any (trash!) initial cycle value.

  3. sorry I forgot to write what task error, in the problem of the pyramid. Although I do not know how other compilers can react to it,I have a hard CODE BLOCKS VISUAL STUDIO and at the second I do not use so far although it is much better

Leave a Reply

Your email address will not be published. Required fields are marked *