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.

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

  1. #include”pch.h”
    #include

    using namespace std;
    void main()
    {
    setlocale(LC_ALL, “ru”);
    int milk, choc, coffe;
    float milkP, chocP, coffeP;
    cout << "Введите кол-во пакетов молока и цену " <> milk >> milkP;
    cout << "Введите кол-во плиток шоколада и цену" <> choc >> chocP;
    cout << "Введите кол-во стиков кофе и цену" <> coffe >> coffeP;
    cout << "Молоко " << milk << " X " << milkP << " = " << milk * milkP << endl
    << "Шоколад " << choc << " X " << chocP << " = " << choc * chocP << endl
    << "Кофе " << coffe << " X " << coffeP << " = " << coffe * coffeP << endl
    << "Итого " << milk * milkP + choc * chocP + coffe * coffeP;

    cout << endl << endl << endl;
    }

  2. #include”pch.h”
    #include

    using namespace std;

    //void main()
    //{
    // setlocale(LC_ALL, “ru”);
    // int milk, choc, coffe;
    // float milkP, chocP, coffeP;
    // cout << "Введите кол-во пакетов молока и цену " <> milk >> milkP;
    // cout << "Введите кол-во плиток шоколада и цену" <> choc >> chocP;
    // cout << "Введите кол-во стиков кофе и цену" <> coffe >> coffeP;
    // cout << "Молоко " << milk << " X " << milkP << " = " << milk * milkP << endl
    // << "Шоколад " << choc << " X " << chocP << " = " << choc * chocP << endl
    // << "Кофе " << coffe << " X " << coffeP << " = " << coffe * coffeP << endl
    // << "Итого " << milk * milkP + choc * chocP + coffe * coffeP;
    //
    //
    // cout << endl << endl << endl;
    //}

  3. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a,b,c;
    int sum;
    cout<<"Введите стоимость шоколадки="<>a;
    cout<<"Стоимость шоколадки="<<a<<endl;
    cout<<"Введите стоимость кофе="<>b;
    cout<<"Стоимость кофе="<<b<<endl;
    cout<<"Введите стоимость молока="<>c;
    cout<<"Стоимость молока="<<c<<endl;
    sum=a+b+c;
    cout<<"Общая стоимость покупки="<<sum<<endl;
    }

  4. 1.
    #include
    using namespace std;

    int main() { // number of goods
    setlocale (0,”russian”);
    int = choco 5;
    int coffe = 2;
    int milk = 2;
    float onEchcko = 89.5;
    float onEcoffe = 192.68;
    float onEmilk = 34.90;
    float sym = (choco * onEchcko) + (coffe * onEcoffe) + (milk * onEmilk);
    std::cout << "общая сумма покупки – " << sym << endl;
    return 0;
    }

  5. #include “pch.h”
    #include
    #include
    using namespace std;

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

    int a, b, c;

    cout <> a;
    cout << endl;

    b = a + 3;
    c = a + b;

    cout << "Вторая переменная равна " << b;
    cout << endl;
    cout << "Третья переменная равна " << c;
    cout << endl;

    }

    //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.

  6. int a, b, c, d;

    cout <> a;
    cout << endl;

    b = a;
    c = a;
    d = a * 3;

    cout << "Количество предметов на столе: " << d;
    cout << endl;

    }

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

  7. #include “pch.h”
    #include
    using namespace std;

    void shop() {
    float milk = 40.1, chocolate = 89.5, coffee = 198.89;
    int value;
    cout <> value;
    milk *= value;
    cout <> value;
    chocolate *= value;
    cout <> value;
    coffee *= value;
    cout << "Покупка будет стоить вам: " << milk + chocolate + coffee << " pybley" <> a;
    b = a + 3;
    c = a + b;
    cout << a << b << c;
    }
    void servTable() {
    int a, b, c;
    cout <> a;
    c = b = a;
    cout << "Кол-во чашек: " << a << "\nКол-во ложек: " << b << "\nКол-во блюдец: " << c << endl;
    }

    int main()
    {
    setlocale(LC_ALL, "rus");
    shop();
    variebls();
    servTable();
    }

Leave a Reply

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