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. Looked comments ... Those who do not appear on the Russian letters must be added immediately to the program setlocale(0, «russian»);
    i.e.. int main(){ setlocale(0, «russian»); continue to write code}

    In response to the program passed checks, which in the future can only hurt the future of good programmers.

    I spread his solution to problems:

    #include
    #include
    #define line cout << "—————————————" << endl;

    using namespace std;

    int main()
    {
    setlocale(0, "russian");
    cout << "1 задача" << endl;
    double result, countOfProducts, chocolate = 20.50,coffee=30.45,milk = 40.0;

    cout countOfProducts;
    system(«cls»);
    result = countOfProducts * chocolate;
    cout countOfProducts;
    system(«cls»);
    result += coffee * countOfProducts;
    cout countOfProducts;
    system(«cls»);
    result += milk * countOfProducts;

    (result < 0) ? cout << "Одно или несколько введенных значений некорректны!":
    cout << "Сумма покупки составит: " << result << " рублей\n" << endl;
    line;

    /* 2 задача */
    cout << "2 задача" << endl;
    int a = 10, b = a + 3, c = a + b;

    cout << c;
    cout << "\n\n";
    line;
    /* 3 задача */
    cout << "3 задача" << endl;
    int cups, spoons, saucer;

    cout cups;
    cout << endl;

    while (cups < 0){
    cout << "Введено неверное количество!\n\n";
    cout cups;
    }
    spoons = saucer = cups;

    cout << "Количество чашек: " << cups
    << "\nКоличество ложек: " << spoons
    << "\nКоличество блюдец: " << saucer;

    _getch();
    return 0;
    }

  2. #include “stdafx.h”
    #include
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_CTYPE, “rus”);
    float a;
    cout <> a;
    float b;
    cout <> b;
    float d;
    cout <> d;
    float c;
    c = a + b + d;
    cout << "Cумма всех покупок равна: " << c << "Грн" << "\n";
    cout << "Считаем заного!\n";
    return main();
    }

    My 1st option to the task,considers the amount of all purchases enter data yourself

  3. A bit complicated 1st task. On the price per unit of cargo(milk, coffee, chocolate). The user enters the number of goods that wants to buy. Next is considered the total price of the goods and the total value of all goods. I think it can be written as something simple but I like xs.

    #include
    #include
    using namespace std;

    int fc1();//функция для подсчета стоимости плитки шоколада
    double fc2();//функция для подсчета стоимости литров молока
    double fc3();//функция для подсчета стоимости граммов кофе
    int a = 3;//цена за плитку шоколада $
    double b = 1.1;//цена за литр молока $
    double c = 0.2;//цена за грамм кофе $
    int chokolate_cost;
    double milk_cost;
    double coffee_cost;
    int main()
    {
    setlocale(LC_ALL, "rus");
    fc1();
    fc2();
    fc3();
    int chokolate;
    double milk, coffee;
    chokolate = chokolate_cost;
    milk = milk_cost;
    coffee = coffee_cost;
    cout << "Общая стоимость " << chokolate + milk + coffee <<"$"<< endl;

    system("pause");
    return 0;

    }

    int fc1()
    {
    int a1;
    cout << "Введите кол-во плиток шоколада, которое вы желаете приобрести. Цена: 3$ за плитку. " <> a1;
    chokolate_cost = a1*a;
    cout << "Стоимость плиток шоколада " << chokolate_cost << "$" << endl;
    return chokolate_cost;
    }
    double fc2()
    {
    double b1;
    cout << "Введите кол-во литров молока, которое вы желаете приобрести. Цена: 1.1$ за литр. " <> b1;
    milk_cost = b1*b;
    cout << "Стоимость литров молока " << milk_cost << "$" << endl;
    return milk_cost;

    }
    double fc3()
    {
    double c1;
    cout << "Введите кол-во грамм кофе, которое вы желаете приобрести. Цена: 0.2$ за грамм. " <> c1;
    coffee_cost = c1*c;
    cout << "Стоимость грамм кофе " << coffee_cost << "$" << endl;
    return coffee_cost;
    }

    1. #include
      using namespace std;

      int main(void)
      {
      system("color 71");

      float milkPrice = 10.5;
      int milk;
      float coffeePrice = 5.8;
      int coffee;
      float chocolatePrice = 7.7;
      int chocolate;
      float total;

      cout << "how much milk are you want?(L)" <> milk;
      cout << "how much coffee are you want?(GR)" <> coffee;
      cout << "how much chocolate are you want?(GR)" <> chocolate;

      cout << "your price for milk is: " << milkPrice * milk << endl;
      cout << "your price for coffee is: " << coffeePrice * coffee << endl;
      cout << "your price for milk is: " << chocolatePrice * chocolate << endl;
      total = (milkPrice * milk) + (coffeePrice * coffee) + (chocolatePrice * chocolate);
      cout << "TOTAL: " << total << endl;;

      return 0;
      }

      Why so cool with functions, if you can make it much more accessible?
      task something very unpretentious

    2. Можно еще чуточку усложнить, давая возможность пользователю самостоятельно указывать не только количество, но и цену товара

  4. I was not under the Google Chrome hand, but I checked in Yandex Browser and the latest Opera: and 1st, and 2, and 3rd browser – is a clone of one basic browser Chromium.
    Everywhere everything is fine revealed.
    So it is you're doing something wrong.

  5. Wow!!! How then turned to the account of the first task!!! I do not know who may need it, I spread his solution to this problem ;)

    #include
    using namespace std;

    int main()
    {
    setlocale (0,"rus");
    int a, b, c, d, e, f;
    cin >> a;
    cout << a;
    cin >> b;
    cout << b;
    cin >> c;
    cout << c;
    cin >> d;
    cout << d;
    cin >> e;
    cout << e;
    cin >> f;
    cout << f;
    int g = a * b + c * d + e * f;
    cout << "Общая сумма затраченная на продукты в грн." << g << endl;
    return 0;
    }

  6. Great puzzles and brain does not dry out…if anyone knows the collections of such puzzles for C ++ …drop links…

Leave a Reply

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