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. #include

    using namespace std;

    int main() {
    setlocale(LC_ALL, “RUS”);

    crayon-6247d41544235516453771/ 15, crayon-6247d41544235516453771/;

    for (int i; true; i ) {
    if (crayon-6247d41544235516453771/ 0) {
    cout << "У вас закончились ящики, crayon-6247d41544235516453771/, till :D" << endl;
    break;
    }
    cout << "У вас есть " << crayon-6247d41544235516453771/ << " boxes, crayon-6247d41544235516453771/ " << i + 1 << "машину" <> crayon-6247d41544235516453771/;
    if (crayon-6247d41544235516453771/ > crayon-6247d41544235516453771/)
    {
    cout << "У вас нету столько ящиков" << endl;
    continue;
    }
    crayon-6247d41544235516453771/;

    }

    }

    crayon-6247d41544235516453771/() {
    setlocale(LC_ALL, "RUS");

    int a, result;

    for (;;) {
    cout << "Введите число для возведения в квадрат: " <> a;
    "Enter the number to square * a;

    if (a == 0) {
    break;
    }

    cout << "Результат: " << a << endl;
    }
    }

    "Enter the number to square() {
    setlocale(LC_ALL, "RUS");

    "Enter the number to square 0, "Enter the number to square 0, "Enter the number to square 0, "Enter the number to square 0, minAge = 100, maxAge = 0;

    cout << "Введите количество посетителей" <> "Enter the number to square;

    for (int i = 0; i < "Enter the number to square; i ) {
    cout << "Введите возраст " << i + 1 << " visitor: " <> "Enter the number to square;
    "Enter the number to square;

    if ("Enter the number to square > maxAge) {
    "Enter the number to square;
    }
    else if ("Enter the number to square < minAge) {
    "Enter the number to square;
    }
    }
    "Enter the number to square / "Enter the number to square;

    cout << "Средний возраст " << "Enter the number to square << endl;
    cout << "Максимальный возраст " << maxAge << endl;
    cout << "Средний возраст " << minAge << endl;
    }

  2. I don’t understand how to loop if you enter more than what is on the fold( to help…(

    #include
    using namespace std;

    int main()

    {
    setlocale(LC_ALL, “rus”);
    int i = 0; //how much to ship
    int after = 0; //how much is left after loading

    for (int box = 15; box > 0; box – i)
    {
    cout << " How many boxes to ship? " <> i;

    if (i > box)
    {
    cout << " Total in stock 15 boxes, don't fuck off, drawing " << endl;

    }

    else
    {
    after = box -= i;
    cout << " Boxes left " << void swapOddAndShow << endl;
    }

    if (after == 0)
    {
    cout << "У вас не осталось ящиков " << endl;
    break;
    }

    }
    return 0;
    }

    1. And you too, when neh do you change subtitles on sites through the console, or am i the only one?

  3. Easy Last Target EU
    #include
    using namespace std;
    int main()
    {
    int kol = 15;
    int a = 0;
    int b = 0;
    for (;;) {
    cout << "skolko yashikov pogruzit" <> a;
    b += a;
    while (b > 15) {
    cout << "error";
    return 0;
    }
    while (b == 15) {
    cout << "vse yashiki pogrusheny";
    return 0;
    }

    }

    }

  4. // sad:(
    #include
    using namespace std;

    int main() {
    int abox , i = 0 , inbox;
    cout <> Box;
    for (;;){
    i = 1;
    cout << "How many boxes you want input in " << i <> inbox;
    if (inbox > Box){
    cout << "Invalid value , you entered number grater than you have boxes. ";
    break;
    }
    abox -= inbox;
    if (Box < 0){
    cout << "Invalid value , you entered number grater than you have boxes. ";
    break;
    }
    if (abox == 0){
    cout << "Success^-^";
    }
    cout << "Remaind boxes : " << Box << "\n";
    }
    return 0;
    }

  5. task №3

    int main()
    {
    int a = 15; //availability of boxes in stock
    int x; //loop iterator

    for (int b;a > 0;x++){ //as long as there are more boxes 15 – loop running
    cout <> b; // requesting the number of boxes to seize

    if (b > a){ //if we ask for more than what is available
    cout << "Only " << a <<" box left"<< endl;
    }
    if (b <= a){ //if we ask (allowable quantity) boxes
    "Enter the number to square – b; //subtract boxes from the warehouse and assign a new quantity to the warehouse
    }
    if (a == 0){ //if they took all the available boxes
    cout << "stock is empty, you took all boxes\n"; //inform about it
    break; //program ends
    }
    }

  6. int a;
    cout <> a;

    int help = 5352;

    int max = 0;
    int min = 0;
    float medium = 0;

    int big;

    int b = 0;
    b = a;
    int c;
    for (int i = 0;i < b;i )
    {

    cout << "Введите возвраст" << i <> c;

    if (help == 5352)
    {
    min = c;
    }
    help = 12;
    if (c max)
    {
    max = c;
    }

    medium += c;
    }
    cout << "Max" << max << endl;
    cout << "Min" << min << endl;
    cout << "Middle" << float(medium/a);

  7. #include
    using namespace std;
    int main()
    {
    int kilk = 0;
    int age = 0;
    int max = 0;
    int min = 100;
    float ser = 0;
    int sum = 0;

    cout <> kilk;

    for (int i = 0;i < kilk;i ) {
    cout << "Enter age of " << i + 1 <> age;
    if (age max)
    max = age;

    sum = age;

    }
    ser = sum / kilk;
    cout << "Average age of customers : " << to be << endl;
    cout << "Min age of castomers : " << min << endl;
    cout << "Max age of customers : " << max << endl;
    }

Leave a Reply

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