The basics of programming in c++ for beginners

Tasks: Select if and else statements in c ++

After reading the lesson aboutSelect if and else statements, go to practice. As usual, I ask you to try to solve all tasks independently, and only then look at proposed us decision.

1. The first task is interesting and fairly simple. But the code will succeed long. This task came up with our teachers of computer Academy. The idea was to – how to get beginning students suffer with writing code, to scribbling was more )))  The task: The user enters the number of the 1 to 9999 (the amount of the issuance of an ATM). It should display the words entered by the amount and in the end to write the name of the currency with the correct ending. For example: 7431 – seven thousand four hundred thirty-one Dollars_, 2149 – two thousand one hundred forty-nine dollars_, 15 – fifteen dollars_, 3 – three dollars_. To solve this task you will need to use the operator % (remainder of the division). Read about it in an article, you can Arithmetic operations in C ++  . Start!

2.  The user enters the serial number of the finger. It should show its name on the screen.

 3. Another challenge for yourself solutions. You must write a program, which checks the user on the knowledge of the multiplication table. The user enters two single-digit numbers. The program asks the question: the result of multiplying the first day of the second.  The user must enter a response and see on the screen is correct or not, he said,. If not– show yet and the correct result.

Those who can not cope – ask questions in the comments.

369 thoughts on “Tasks: Select if and else statements in c ++

  1. [code]
    #include
    using namespace std;
    int main()
    {

    setlocale(LC_ALL, “rus”);
    int ival1 = 0;
    int ival2 = 0;
    int ival3 = 0;
    cout << "введите 2 and the third number—the multiplication result:"
    cin >> ival1;
    cin >> ival2;
    cin >> ival3;
    if (ival1*ival2 == ival3)
    cout << "замечательно умножаете!!!";
    else
    cout << "тут ошибка!!!";
    }
    [/code]

    1. It is certainly remarkable, but the task is said: The user enters two single-digit numbers. Unambiguous, and you have completed the program in which you can enter any number, you need to add a loop to check the entered numbers on the number of characters. The multiplication table of 1 to 9

      1. Something like this….
        [code]
        #include
        using namespace std;

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

        int number1 = 0;
        int number2 = 0;
        int result = 0;

        cout <> number1;
        if ((number1 >0) && (number1 <10))
        {
        cout <> number2;
        if ((number2 >0) && (number2 <10))
        {
        cout << "Result " << number1 << "*" << number2 <> result;
        int goodResult = 0;
        goodResult = number1 * number2;
        if (goodResult == result)
        cout << "Perfect" << endl;
        else
        cout << "Error " << number1 << "*" << number2 << "=" << number1*number2 << endl;
        }
        else
        cout << "Fuck you need to 1 – 9" << endl;
        }
        else
        cout << "Fuck you need to 1 – 9" << endl;

        return 0;
        }
        [/code]

  2. 2 a task

    [code]
    /*The user enters the serial number of the finger.
    It should show its name on the screen. * /

    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “Rus”);
    int number;
    cout << "Введите номер пальца"
    cin >> number;
    if (number = 6)
    cout << "Вы ввели неверный номер!" << endl;
    else
    {
    if (number == 1) cout << "Большой палец" << endl;
    else if (number == 2) cout << "Указательный палец" << endl;
    else if (number == 3) cout << "Средний палец" << endl;
    else if (number == 4) cout << "Безымяный палец" << endl;
    else if (number == 5) cout << "Мезинец палец" << endl;
    }
    system("pause");
    return 0;
    }
    [/code]

  3. I am waiting for advice and editing from pros :

    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “russian”);
    int first = 0;
    int second = 0;
    int third;

    do {
    cout << "Введите два однозначных числа (0 to exit)\n";
    cout <> first;
    if(first == 0) return 0;
    cout <> second;

    while(first != second) {
    cout << "Числа не однозначны!\n";
    cout <> first;
    if(first == 0) return 0;
    cout <> second; }

    cout <> third;

    if(first * second == third)
    cout << "Правильно!\n";
    else cout << "Неправильно!\n" << "Правильный вариант ответа: " << first * second << "\n";
    } while (third != 0);

    return 0;
    system("pause");

    }

  4. Regarding the first task. I am in my life would not have thought of such a thing. Opening decision, got it, but how to think of it before this question. Generally where to start, such programming is such a thing as a block diagram, I just heard about it. but I do not know how to use it. On the other tasks issues have arisen, pretty simple.

  5. The first task: thousands of text or small letters, or complicate and automatically change to hundreds, tens and units.

  6. #include

    using namespace std;

    int main()
    {
    cout << "\t\t***tabl_umNojeNia***\n\n"<< endl;

    int a, b, res;

    cout <> a >> b;

    if (a > 10 || a < 2)
    {
    cout < 10 || b < 2)
    {
    cout << " error! \n";
    return -1;
    }

    cout <> res;

    int i;

    i = a*b;

    if (res > i || res < i)
    {
    cout << "incorrect answer!!!\n " << i;
    }

    if (res = i)
    {
    cout << " correct answer)";
    }

    return 0;
    }

  7. #include
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a, b, c, d, e;
    cout << "Ââåäèòå ïåðâóþ öèôðó: " <> a;
    cout << "Ââåäèòå âòîðóþ öèôðó: " <> b;
    cout << "Íàçîâèòå êàêîâ ðåçóëüòàò: " <> c;
    d = a * b;
    if (c !=d)
    {
    cout << "Âàø îòâåò íå âåðíûé ìóäàê!!!" << endl;
    cout << "Íàæìè íà êíîïêó ÷òîáû óçíàòü ïðàâèëüíûé îòâåò " <> e;
    cout << "Âàø îòâåò ðàâåí: " << d << endl;
    }
    else if (c==d)
    {
    cout << "Âû ââåëè ïðàâèëüíûé îòâåò, îäèí õóé òû ìóäàê!!! " << endl;
    cout << "Âàø îòâåò ðàâåí: " << d << endl;
    }

    return 0;
    }

Leave a Reply

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