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. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “ru”);
    int milk;
    int chocolate;
    int coffee;
    float $milk;
    float $chocolate ;
    float $coffee;
    cout << "Введите количество пачек молока" <> milk;//we enter the number of packs into the variable
    cout << "Введите цену молока" <> $milk;
    cout << "Введите количество пачек шоколада" <> chocolate;
    cout << "Введите цену шоколада" <> $chocolate;
    cout << "Введите количество пачек кохфе" <> coffee;
    cout << "Введите цену кохфе" <> $coffee;
    float sum = 0;
    cout << "молоко + chocolate + кохфе = ";
    cout << (milk * $milk) + (chocolate * $chocolate) + (coffee * $coffee)<<endl;//consider the cost
    return 0;
    }

  2. #include
    using namespace std;
    int main() {
    setlocale(LC_ALL, “Russian”);
    int chocolate, coffee, milk;
    double chocolate0price;
    double coffee0price;
    double milk0price;
    cout << "Введите количество шоколада: " <> chocolate;
    cout << "Введите стоимость шоколада: " <> chocolate0price;
    cout << "Введите количество кофе: " <> coffee;
    cout << "Введите стоимость кофе: " <> coffee0price;
    cout << "Введите количество молока: " <> milk;
    cout << "Введите стоимость молока: " <> milk0price;
    double sum = ((chocolate * chocolate0price) + (coffee * coffee0price) + (milk * milk0price));
    cout << "Общая сумма покупок: " << sum << " b.r. " << endl;
    return 0;
    }

    1. Будь внимателен и посмотри ошибки в консоли они там есть и достаточно что сократил на несколько обзатцов .

  3. int main()
    {
    setlocale(LC_ALL, “rus”);

    int spoon, fork, cup, sauces, total;

    cout <> spoon;
    cout << "ложки: " << spoon << endl;

    cout <> fork;
    cout << "вилок: " << fork << '\n';

    cout <> cup;
    cout << "чашек: " << cup << '\n';

    cout <> sauces;
    cout << "блюдцев: " << sauces << '\n';

    total = spoon + fork + cup + sauces;
    cout << "Всего: " << total << endl;

    return 0;

    }

  4. Ты ответ дай и увидишь что это правильно , подумай головой , а не ешь ней

  5. Ответ дай и тогда узнаешь что это правильно подумай головой, а не ешь ней

  6. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int milk;
    int cofee;
    int chocolate;
    cout << "Введите цену молока." <> milk;
    cout << "Введите цену кофе." <> cofee;
    cout << "Введите цену шоколада." <> chocolate;
    cout << milk + cofee + chocolate << endl;
    }

  7. #include

    using std::cout; using std::cin; using std::endl;

    int main() {
    double coffe, milk, choco, coffe$, milk$, choco$;
    cin >> coffe >> milk >> choco >> coffe$ >> milk$ >> choco$;
    cout << coffe * coffe$ + milk * milk$ + choco * choco$;

    return 0;
    }

Leave a Reply

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