The basics of programming in c++ for beginners

Tasks: A for loop in c ++

Once you begin to tasks,  therefore already know what for loop. Let's look at a few of the tasks, solution in which it is applied, and, thereby, strengthen the knowledge gained. Programming practice– the best way to deal with the material and store information for a long time.

1. Write a program, that will show on the screen the number of the square,  entered by the user. The user has to decide for himself –  exit the program or continue writing. (Tip – You must run an infinite loop, which provide for termination of his, upon the occurrence of certain conditions).

2. In the gym every day comes a certain number of visitors. It should prompt the user to enter such data: how many people visited the gym for the day, enter the age of each visitor and ultimately show the age of the oldest and the youngest of them, as well as to calculate the average age of visitors.

For the job yourself, We offer you to solve a similar task. Arrange the number of visitors entering the gym and the number of hours spent by each of them in the gym. As a result, calculate and display the total amount, which customers have paid for training.

 3. In stock has a certain number of boxes of apples (in this example, 15). When the car arrives for pickup, ask the user to enter, how many boxes loaded into the first car,  the second and so on, until there are no more boxes of apples. Provide case, When the user enters the number of boxes more, than there is in stock.

If you have questions, please contact us in the comments.

161 thoughts on “Tasks: A for loop in c ++

  1. The second and more 3 tasks:

    1. #include
      using namespace std;
      int main()
      {
      int base;
      int power;
      long long result=1;
      cout<>base>>power;

      for(int i=1;i<=power;i )
      {
      result*base;
      }
      cout<<"Result is"<<result;
      return 0;
      }

    2. У вас не корректно сработает программа по третьей задаче, если кол-во загружаемых ящиков будет больше чем есть на складе.

      cout kolLoadBox;
      kolBox = kolBoxkolLoadBox; у вас тут может получиться “-”
      cout << "Ящиков осталось на складе: " << kolBox << endl;
      if (kolBox <=0) break;
      for example: kolBox = 15
      первая машина запросила 10
      kolBox = kolBoxkolLoadBox
      left 5 boxes, следующая машина просит 7
      у вас посчитается и на складе будет -2 box.

  2. please help make!

    Skier, starting exercise, on the first day ran n km. Every day he increased the mileage on m% from the previous day's run. How many kilometers he will run for k days.

    1. double n;
      double m;
      Int k, S;
      cin>>n>>m>>k;
      for (i = 1; i < =k; i )
      S=((n + m)+m)*k;
      cout<<k;
      return ;
      }

  3. task N3

    1. editor site spoils code entry – eats characters between the opening and closing angle brackets.
      So I 100 once he wrote in different themes: Do not write your code here!
      Why did you write the code here?
      Want to brag?
      Or you want to praise?
      So not praise you for that: at your place … as well as all other students – very mediocre ;-).
      And if you want your code pokritikoval, then please contact us here:
      http://rus-linux.net/forum/viewforum.php?f=31

  4. Why is a sign not of equality can not understand the first task :( if (exit != 'And’ && exit != 'Y').

    1. Because if you enter something, anything Besides 'Y’ или 'Y’ (не 'and’ and не 'Y') – then you have not yet matured to exit the program.

      1. On the contrary, тут имеется ввиду , чтобы продолжить вы должны ввести именно ‘yили ‘Y’, если введете всё что угодно кроме ‘y’ или ‘Y’, то программа закончит выполнятся.

  5. Given chislo.Vybrosit natures of the record of this number of digits 3 ,leaving unchanged the rest of the order of numbers, if no number 3, then output a predetermined number of(Help ,you are welcome.

Leave a Reply

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