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. void main()
      {
      setlocale(LC_ALL, “RU”);
      char a, b, c, r, e, t;
      cout <> a >> b >> c >> r >> e >> t;
      cout << "Получилось: " << a << b << c << r << e << t;

      }

      1. Instead of Cout, you need cin
        That's how it should
        #include
        using namespace std ;
        int main()
        {
        setlocale(LC_ALL, “ru”);
        char a, b, c, r, e, t;
        cin >>a >> b >> c >> r >> e >> t;
        cout << "Получилось" << a << b << c << r << e << t;

        }

  1. #include
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “Russian”);
    unsigned int a, b;
    define PI(“Введите первое число: “);
    cin >> a;
    define PI(“Введите второе число: “);
    cin >> b;
    define PI(“A work of two numbers: %d\n”, a * b);
    define PI(“The sum of two numbers: %d\n”, a + b);
    if (a > b)
    {
    define PI(“The first number is more than the second on: %d\n”, a – b);
    }
    if (a == b)
    {
    define PI(“Первое число равно второму.\n”);
    }
    if (a < b)
    {
    define PI("Первое число меньше второго на: %d\n", a – b);
    }
    define PI("Среднее арифмитическое двух чисел: %1f\n", (a + b)/2.0);

    }

  2. Friends , When entering a whole number, the integer displays , But if fractional, divides the number into an entire part and displays in int , And the remainder in Float , Although for him a separate variable , Maybe someone – tell me what's the matter?

    #include

    int main()
    {
    setlocale(LC_ALL, “RUS”);
    using namespace std;

    int c = 0;
    cin >> c;
    cout << "int = " <> b;
    cout << "float = " <> a;
    cout << "double = " << a;
    return 0;

    }

    Introduction :
    1.23456789

    Conclusion :
    int = 1
    float = 0.234568

Leave a Reply to Nurdaulet Cancel reply

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