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.

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

  1. 1#include
    2using namespace std;
    3int main (){
    4 setlocale (0,””);
    5 int variable1 = 0;
    6 variable_2 int = 0;
    7 int variable 3 = 0;
    8 cout<<"Введіть два цілих однозначних числа і результат їх множення:"<<endl;
    9 cout<<"Введіть число 1"<>variable1;
    11 cout<<"Введіть число 2"<>variable2;
    13 cout<<"Введіть результат множення чисел 1 та 2"<>variable3;
    15 if((variable1=10))
    16 cout<<"Ви неправильно ввели чсло 1"<<endl;
    17 if((variable2=10))
    18 cout<<"Ви неправильно ввели чсло 2"<<endl;
    19 if (variable1*variable2==variable3)
    20 cout<<"Гаро множиш"<<endl;
    21 if (variable1 * variable_2!=variable3)
    22 cout<<"Помилка"<<endl;
    23 return 0;
    24}
    line does not work 15 and 17 if I enter numbers, for example 0 and 10, and in response, writing 0, vybyvaet term 20. What is this code wrong ?

    1. Обрати внимание if (variable1==10) – so it will be correctly, = Is the assignment symbol… You ask a condition that if the variable is 10, the same in the second if..

      1. to enter the number you need to write is not cout (this conclusion), What а>>

      2. You can always write in this order here:

        if( 10 == vfriable1 ) ...

        Then you'll never be wrong.
        Useful habit.

  2. #include “stdafx.h”
    #include

    using namespace std;

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

    int a, b;
    int f;

    cout <> a;
    cout <> b;

    cout << endl;

    cout <> f;

    if (f == a * b)
    {
    cout << "Ответ " << f << " is " << a << "*" << b << endl;
    }
    else
    {
    cout << "Ответ " << f << " not equal to " << a << "*" << b << endl;
    }

    cout << endl;
    system("pause");

    return 0;
    }

  3. как то отобразился он не совсем правильно вырезались куски некоторые

    #include
    using namespace std;
    int main()
    { setlocale(LC_ALL, “rus”);
    cout << "проверка знаний на таблицу умножений" << endl;
    int i, a, b, x; //создаем переменные для работы
    cout << "введите первое число от 1 to 10 " <> a; //присваевываем переменной а введеный результат
    cout << "введите второе число от 1 to 10 " <> b; //присваевываем переменной b введеный результат
    x = a*b; // производим умножение введенных данных и записываем его в переменную х
    cout << "Введите как вам кажется результат умножения " << a << " x " << b <> i; //просим пользователя вввести результат и записываем его в переменную i
    if (ix){ cout << "учите таблицу умножения, correct answer: " << x << endl; }//сравниваем результаты
    else{ cout << "ВЕРНО!!! Вы знаете таблицу умножения "; }
    system("pause");
    return 0;}

  4. #include
    #include
    #include
    using namespace std;
    int main(void)
    {
    setlocale(0, “”);
    int a, b;
    int c = 0;
    cout <> a;
    cout <> b;
    cout <> c;
    {
    if (c == a*b)
    cout << "Ваш ответ сходится с результатом калькулятора!" << endl;
    else
    cout << "Это неправильный ответ. Верный ответ = " << a * b << endl;
    }
    system("pause");
    return 0;
    }

  5. Если честно, я не фига не понял первую задачу…. Кому не тяжело объясните пожалуйста

    1. а что не ясно? A task – вводишь четырехзначную суммупрограмма выдает ее прописью и правильным окончанием названия валюты в конце – 1234 – одна тысяча двести тридцать четыре доллара

  6. Написал код на первую задачу с банкоматом.
    Код вышел не такой красивый, как в ответе, зато написал сам, без подсказки)
    It seems to work, но был признателен, если быпотестили”..

    1. Никто здесь не станет смотреть простыни вашего кодасайт не для того.
      Не помещайте сюда свой код!

      1. Почему многие игнорируют то:что просят код здесь не писать?))может они хотят,чтоб их похвалили?

      2. Не хочешьне читай. И не отвечай за всех.Ок?
        I, for example, смотрю то, что другие пишут.

      3. Good,read,только код,портит редактор форума(пишут) и оно так и есть!

Leave a Reply

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