The basics of programming in c++ for beginners

Tasks: Data input and output

In a previous articleData output on the screen and in theentray data from the keyboard We examined in detail this topic. It's time to practice – because we have a lot of work, to develop certain skills, needed a programmer and develop their logical thinking quietly.

1. Create 4 variables with different types of data and ask the user to enter values ​​in them. After entering the, display them on the screen.

2. Create 5 variables of type char, ask the user to enter a word of five letters, and show these symbols (the word) the screen. (Enter characters in Latin, tk. cyrillic is displayed incorrectly. Why? This will be discussed in one of our next lessons)

3. Display the text in this form:

data display

4. The user must enter 2 numbers. You need to show on the screen the product of these numbers, sum and difference. Show the same arithmetic mean of these numbers entered.


Questions to ask in the comments.

74 thoughts on “Tasks: Data input and output

  1. #include ;
    using namespace std;

    crayon-620a9ebe8fb50629382471/()
    {
    setlocale(LC_ALL, “ru”);

    char a, b, c, d, e;

    cout << "Введите буквы по порядку" <> a >> b >> c >> d >> e;

    cout << "Ваше слово – " << a << b << c << d << e;

    return 0;
    }

    1. what's the problem with using string, well, or getline(), if there are spaces in the line? And so it turns out that after each character you need to enter a space

  2. #include
    using namespace std;

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

    cout << "\a\a\a\a\a\n";
    cout << " Why doesn't she ever like it in a restaurant?,\n";
    cout << " She ordered that the, and always like it, what did I order?\n";
    cout << " And she begins to eat from my plate. I tell her:\n";
    cout << " \"Закажи себе то же самое\". Она говорит \"Зачем? \n";
    cout << " Я только попробовать\". И съедает половину.\n";
    cout << " //k.f.. \"О чём говорят мужчины\"//\n";

    return 0;
    }

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

    int digit = 0;
    double digit2 = 0;
    char symbol = 0;
    bool trueOrFalse = 0;

    cout <> digit;
    cout <> digit2;
    cout <> symbol;
    // в переменную типа bool с помощью cin можно ввести
    // только числа 0 (интерпретируется как false) and 1 (true)
    cout <> trueOrFalse;

    cout << endl << endl;
    cout << "Целое число: " << digit << endl;
    cout << "Вещественное число: " << digit2 << endl;
    cout << "Символ: " << symbol << endl;
    cout << "bool: " << trueOrFalse << endl;

    return 0;
    }
    What am I doing wrong ?? The very first data entry works for me and then it just crashes, and I can't enter anything else. Whoever saw my mistake, please respond to my comment

    1. int main()
      {
      int ferstName;
      float youAge;
      double likeYou;

      cout <> ferstName;
      cout <> youAge;
      cout <> likeYou;

      cout << endl << endl;
      cout << "Your Ferst Name:" << ferstName << endl;
      cout << "Your old age:" << youAge << endl;
      cout << "thing becouse your like:" << likeYou << endl;

      return 0;

      }

  4. #include

    using namespace std;

    int main()
    {

    setlocale(LC_ALL, “Russian”);

    int a;
    char b;
    float c;
    double d;

    cout <> a;

    cout <> b;

    cout <> c;

    cout <> d;

    cout << "\nВсе типы данных которые вы ввели по очерености: " << a << ", " << b << ", " << c << ", " << d;
    }

  5. #include

    using namespace std;

    int main()
    {

    setlocale(LC_ALL, “Russian”);

    char a, b, c, d, i;

    cout <> a >> b >> c >> d >> i;

    cout << "\nУ вас получилось слово: " << a << b << c << d << i << "\n";

    cout << "Ваша первая буква: " << a;
    cout << "\nВаша вторая буква: " << b;
    cout << "\nВаша третья буква: " << c;
    cout << "\nВаша четвертая буква: " << d;
    cout << "\nВаша пятая буква: " << i;
    }

  6. #include

    using namespace std;

    int main()
    {

    setlocale(LC_ALL, “Russian”);

    float a, b, composition ,sum, difference, mean, d;

    cout <> a;

    cout <> b;

    composition = a * b;
    sum = a + b;
    difference = a – b;
    mean = (a + b) / 2;

    cout << "Произведение двух чисел: " << composition;
    cout << "\nСумма двух чисел: " << sum;
    cout << "\nРазница двух чисел: " << difference;
    cout << "\nCреднее арифметическое двух чисел: " << mean;
    }

Leave a Reply

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