The basics of programming in c++ for beginners

Tasks: Data types, variables and constants

Here are collected the task to the article Data types, variables and constants. Try to solve problems on their own and only need to look at the decision. So you will learn much faster programming fundamentals.

1. Declare variables with which you can calculate the total amount of the purchase of several products. For example a chocolate bar, coffee and packets of milk.

2. Declare three variables of type int, and the first to assign a numeric value, the second variable is the first variable increased by 3, and the third variable is equal to the sum of the first two.

3. Declare variables, to count the total number of objects for the table. for example cups, the same number of saucers and spoons.

122 thoughts on “Tasks: Data types, variables and constants

  1. I ignored COUT (online compiler)
    #include
    using namespace std;
    int chocoP, milkP, cofeP, chocoC, milkC, cofeC;
    int main() {
    setlocale(LC_ALL, “rus”);
    cout << "Вводите количество шоколадок" <> chocoC;
    cout << "Введите цену шоколадок" <> chocop;
    cout << "Вводите количество молока" <> milkC;
    cout << "Введите цену молока" <> milkP;
    cout << "Вводите количество кофе" <> cofeC;
    cout << "Введите цену кофе" <> cofeP;
    cout << "Сумма шоколадок" << chocoC * chocop << endl;
    cout << "Cумма молока" << milkC*milkP << endl;
    cout << "Cумма кофе" << cofeC*cofeP << endl;
    cout << "ИТОГО " << chocoC * chocop cofeC + * + cofeP milkC * milkP << endl;
    return 0;
    }

    1. cout << "Вводите количество шоколадок" chocoC;
      cout << "Вводите количество молока" milkC;
      cout << "Введите цену молока" milkP;
      cout << "Вводите количество кофе" cofeC;
      cout << "Введите цену кофе" cofeP
      2 стрелочки в разные стороны

  2. second problem was solved by another sympathetic, and then the question is brewing.
    I did everything right tk. It gives the correct answer.

    #include
    using namespace std;

    int main()
    {
    int nm_1 = 11;
    int nm_2 = 0;
    int nm_3 = 0;

    nm_2 = (nm_1 + 3);
    nm_3 = (nm_1 + nm_2);

    cout << nm_3<<endl;

    return 0;
    }

    It gives the correct answer (25)

  3. Why are so many code, here at 2 line vlozhidsya:
    int a = 5, b = a*3, c = a + b;
    cout<<a<<"\n"<<b<<"\n"<<c;

  4. int d;
    cout << "введите количество гостей: " <> d;
    int a = d; //cup
    int b = d; //saucer
    int c = d; //spoons
    int g = a + b + c;
    cout << "Нужно чашек: " << a
    << endl<<"Нужно ложек: " << c
    << endl<<"нужно блюдец: " << d
    << endl<<"всего предметов= " << g << endl;

  5. #include
    using namespace std;

    int main()
    {
    cout << "\t\t\t\tПродукти\t\t"<< endl;

    float a = 3.5;
    float b = 2.7;
    float c = 4.8;
    float ad = 0.9855;
    float bd = 0.99;

    cout << "\tЦіна Продуктів: " << " Milk = 3.5 $ t Meat = 2.7 $ t $ 4.8 Chocolate =" <<endl;

    int aNumber;
    int bNumber;
    int cNumber;

    cout <> aNumber;
    cout <> bNumber;
    cout <> cNumber;
    float sum1 = ( a * aNumber );
    float sum2 = ( b * bNumber );
    float sum3 = ( c * cNumber );

    float PriceOfProducts = ( sum1 * ad ) + ( sum2 * bd ) + sum3;
    float PriceOfMilk = sum1 * ad;
    float PriceOfMeat = sum2 * bd;
    cout << " Price of Milk: " << sum1 << "$" << "\t\tЗа знижкою:" << PriceOfMilk << "$" <<endl;
    cout << " Price of meat: " << sum2 << "$" << "\t\tЗа знижкою:" << PriceOfMeat << "$" << endl;
    cout << " chocolate Price: " << sum3 << "$" << "\tЗнижка відсутня" << endl;
    cout <” << endl;

    cout << "\t\tЦіна Продуктів: = " << PriceOfProducts << "$" << endl << endl;;
    return 0;
    }
    №1-Completed*

    1. #include
      using namespace std;

      int main()
      {
      int first, second, third;

      cin >> first;

      second = first + 3;

      third = first + second;

      cout << "second = " << second << "\n third = " << third;

      return 0;
      }
      №2- Completed

      1. #include
        using namespace std;

        int main()
        {
        int cups, soucer, spoons;
        cin >> cups;
        soucer = spoons = cups;
        cout << "soucer = " << soucer << "\n\t spoons = " << spoons;
        return 0;
        }
        №3-Completed

  6. I like this happened

    setlocale(LC_ALL, “russian”);
    int chokolat, coffee, moloko;
    cout <> Chokolat;
    cout <> coffee;
    cout <> moloko;
    int price = chokolat + coffee + moloko;
    cout << "Общая цена всех продуктов" << price <<"\n";

  7. The first made pokrasivshe
    #include “pch.h”
    #include

    using namespace std;

    int main()
    {
    setlocale(0, “”);

    int chocolate;
    int milk;
    int coffee;
    cout <> chocolate;
    cout <> milk;
    cout <> coffee;
    float priceOfChocolate = 11.04;
    float priceOfMilk = 9.59;
    float priceOfCoffee = 70.77;

    float sum = 0;
    sum = (chocolate * priceOfChocolate) + (milk * priceOfMilk) + (coffee * priceOfCoffee);

    cout << "Общая стоимость покупки = " << sum << endl;

    return 0;
    }

Leave a Reply

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