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. Проверяю код до отправления комментария-все ок, проверяю после-белиберда..во дела)

  2. Вы сами понимаете какие вы тупые задачи делатете? Вы про сто что

  3. #include
    using namespace std;

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

    int first = 0;
    int second = 0;
    int transfer_user = 0;
    int transfer = 0;

    cout <> first >> second;
    transfer = first * second;

    cout <> transfer_user;

    if (transfer_user == transfer)
    cout << "Ваш ответ верный!";
    else
    cout << "Выучите таблицу умножения!";
    }

  4. #include
    using namespace std;

    int main() {

    setlocale(0, “Russian”);
    int x, Y, from;
    cout << "\t\tВспомним таблицу умножения!" << endl << endl;
    cout <> x;

    cout <> Y;

    cout << "Чему будет равно произведение этих чисел?" <> from;
    if (z == x * Y) cout << "Это правильный ответ" << endl << endl;
    else cout << "Вы ввели не верный ответ! Correct answer : " << x * Y << endl << endl;

    system("pause");
    return 0;
    }

  5. #include
    using namespace std;

    int main() {
    setlocale(LC_ALL, “ru”);
    int FirstNumber = 0;
    int SecondNumber = 0;
    int answer;
    cout << "Сейчас мы проверим твое знание таблицы умножения!\n";
    cout <> FirstNumber;
    cout <> SecondNumber;
    cout << "Отлично, ты ввел " << FirstNumber << " and " << SecondNumber << "." << endl;
    int SecondAndFirst = FirstNumber * SecondNumber;
    cout <> answer;
    if (answer != SecondAndFirst) {
    cout << "\nНеверно! Correct answer " << SecondAndFirst;
    }
    if (answer == SecondAndFirst) {
    cout << "\nУмничка!";
    }
    return 0;
    }

  6. #include

    using namespace std;

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

    int a,b,c;

    cout <> a;
    cin >> b;
    cout << "Напиши ответ " << a << "*" << b <> c;

    if (c == a * b) cout << "Верно!";
    else cout << "Не верно!";
    }

  7. #include
    using namespace std;

    int main()
    {
    setlocale(LC_CTYPE, “Russian”);
    int a = 0, b = 0, c = 0, d = 0, e = 0;
    cout <> a;
    cout <= 0 and a = 1000)
    {
    b = a / 1000;
    if (b == 1)
    cout << "Одна тысяча ";
    else if (b == 2)
    cout << "Две тысячи ";
    else if (b == 3)
    cout << "Три тысячи ";
    else if (b == 4)
    cout << "Четыре тысячи ";
    else if (b == 5)
    cout << "Пять тысяч ";
    else if (b == 6)
    cout << "Шесть тысяч ";
    else if (b == 7)
    cout << "Семь тысяч ";
    else if (b == 8)
    cout << "Восем тысяч ";
    else if (b == 9)
    cout << "Девять тысяч ";
    c = a / 100 % 10;
    if (c == 1)
    cout << "сто ";
    else if (c == 2)
    cout << "двести ";
    else if (c == 3)
    cout << "триста ";
    else if (c == 4)
    cout << "четыреста ";
    else if (c == 5)
    cout << "пятьсот ";
    else if (c == 6)
    cout << "шестьсот ";
    else if (c == 7)
    cout << "семьсот ";
    else if (c == 8)
    cout << "восемьсот ";
    else if (c == 9)
    cout << "девятьсот ";
    d = a / 10 % 10;
    if (d == 2)
    cout << "двадцать ";
    else if (d == 3)
    cout << "тридцать ";
    else if (d == 4)
    cout << "сорок ";
    else if (d == 5)
    cout << "пятьдесят ";
    else if (d == 6)
    cout << "шестьдесят ";
    else if (d == 7)
    cout << "семьдесят ";
    else if (d == 8)
    cout << "восемьдесят ";
    else if (d == 9)
    cout << "девяносто ";
    and = a % 10;
    if (d == 1)
    {
    if (e == 0)
    cout << "десять долларов";
    else if (e == 1)
    cout << "одиннадцать долларов";
    else if (e == 2)
    cout << "двенадцать долларов";
    else if (e == 3)
    cout << "тринадцать долларов";
    else if (e == 4)
    cout << "четырнадцать долларов";
    else if (e == 5)
    cout << "пятнадцать долларов";
    else if (e == 6)
    cout << "шестнадцать долларов";
    else if (e == 7)
    cout << "семнадцать долларов";
    else if (e == 8)
    cout << "восемнадцать долларов";
    else if (e == 9)
    cout << "девятнадцать долларов";
    }
    if (d != 1)
    {
    if (e == 0)
    cout << "долларов";
    else if (e == 1)
    cout << "один доллар";
    else if (e == 2)
    cout << "два доллара";
    else if (e == 3)
    cout << "три доллара";
    else if (e == 4)
    cout << "четыре доллара";
    else if (e == 5)
    cout << "пять долларов";
    else if (e == 6)
    cout << "шесть долларов";
    else if (e == 7)
    cout << "семь долларов";
    else if (e == 8)
    cout << "восем долларов";
    else if (e == 9)
    cout <= 100)
    {
    c = a / 100 % 10;
    if (c == 1)
    cout << "Сто ";
    else if (c == 2)
    cout << "Двести ";
    else if (c == 3)
    cout << "Триста ";
    else if (c == 4)
    cout << "Четыреста ";
    else if (c == 5)
    cout << "Пятьсот ";
    else if (c == 6)
    cout << "Шестьсот ";
    else if (c == 7)
    cout << "Семьсот ";
    else if (c == 8)
    cout << "Восемьсот ";
    else if (c == 9)
    cout << "Девятьсот ";
    d = a / 10 % 10;
    if (d == 2)
    cout << "двадцать ";
    else if (d == 3)
    cout << "тридцать ";
    else if (d == 4)
    cout << "сорок ";
    else if (d == 5)
    cout << "пятьдесят ";
    else if (d == 6)
    cout << "шестьдесят ";
    else if (d == 7)
    cout << "семьдесят ";
    else if (d == 8)
    cout << "восемьдесят ";
    else if (d == 9)
    cout << "девяносто ";
    and = a % 10;
    if (d == 1)
    {
    if (e == 0)
    cout << "десять долларов";
    else if (e == 1)
    cout << "одиннадцать долларов";
    else if (e == 2)
    cout << "двенадцать долларов";
    else if (e == 3)
    cout << "тринадцать долларов";
    else if (e == 4)
    cout << "четырнадцать долларов";
    else if (e == 5)
    cout << "пятнадцать долларов";
    else if (e == 6)
    cout << "шестнадцать долларов";
    else if (e == 7)
    cout << "семнадцать долларов";
    else if (e == 8)
    cout << "восемнадцать долларов";
    else if (e == 9)
    cout << "девятнадцать долларов";
    }
    if (d != 1)
    {
    if (e == 0)
    cout << "долларов";
    else if (e == 1)
    cout << "один доллар";
    else if (e == 2)
    cout << "два доллара";
    else if (e == 3)
    cout << "три доллара";
    else if (e == 4)
    cout << "четыре доллара";
    else if (e == 5)
    cout << "пять долларов";
    else if (e == 6)
    cout << "шесть долларов";
    else if (e == 7)
    cout << "семь долларов";
    else if (e == 8)
    cout << "восем долларов";
    else if (e == 9)
    cout <= 10)
    {
    d = a / 10 % 10;
    if (d == 2)
    cout << "Двадцать ";
    else if (d == 3)
    cout << "Тридцать ";
    else if (d == 4)
    cout << "Сорок ";
    else if (d == 5)
    cout << "Пятьдесят ";
    else if (d == 6)
    cout << "Шестьдесят ";
    else if (d == 7)
    cout << "Семьдесят ";
    else if (d == 8)
    cout << "Восемьдесят ";
    else if (d == 9)
    cout << "Девяносто ";
    and = a % 10;
    if (d == 1)
    {
    if (e == 0)
    cout << "Десять долларов";
    else if (e == 1)
    cout << "Одиннадцать долларов";
    else if (e == 2)
    cout << "Двенадцать долларов";
    else if (e == 3)
    cout << "Тринадцать долларов";
    else if (e == 4)
    cout << "Четырнадцать долларов";
    else if (e == 5)
    cout << "Пятнадцать долларов";
    else if (e == 6)
    cout << "Шестнадцать долларов";
    else if (e == 7)
    cout << "Семнадцать долларов";
    else if (e == 8)
    cout << "Восемнадцать долларов";
    else if (e == 9)
    cout << "Девятнадцать долларов";
    }
    if (d != 1)
    {
    if (e == 0)
    cout << "долларов";
    else if (e == 1)
    cout << "один доллар";
    else if (e == 2)
    cout << "два доллара";
    else if (e == 3)
    cout << "три доллара";
    else if (e == 4)
    cout << "четыре доллара";
    else if (e == 5)
    cout << "пять долларов";
    else if (e == 6)
    cout << "шесть долларов";
    else if (e == 7)
    cout << "семь долларов";
    else if (e == 8)
    cout << "восем долларов";
    else if (e == 9)
    cout < 0)
    {
    and = a % 10;
    if (e == 1)
    cout << "Один доллар";
    else if (e == 2)
    cout << "Два доллара";
    else if (e == 3)
    cout << "Три доллара";
    else if (e == 4)
    cout << "Четыре доллара";
    else if (e == 5)
    cout << "Пять долларов";
    else if (e == 6)
    cout << "Шесть долларов";
    else if (e == 7)
    cout << "Семь долларов";
    else if (e == 8)
    cout << "Восем долларов";
    else if (e == 9)
    cout << "Девять долларов";
    }
    else
    cout << "Ноль долларов";
    }
    else
    cout << "Вы ввели неверное число";

    return 0;
    }#include
    using namespace std;

    int main()
    {
    setlocale(LC_CTYPE, “Russian”);
    int a = 0, b = 0, c = 0, d = 0, e = 0;
    cout <> a;
    cout <= 0 and a = 1000)
    {
    b = a / 1000;
    if (b == 1)
    cout << "Одна тысяча ";
    else if (b == 2)
    cout << "Две тысячи ";
    else if (b == 3)
    cout << "Три тысячи ";
    else if (b == 4)
    cout << "Четыре тысячи ";
    else if (b == 5)
    cout << "Пять тысяч ";
    else if (b == 6)
    cout << "Шесть тысяч ";
    else if (b == 7)
    cout << "Семь тысяч ";
    else if (b == 8)
    cout << "Восем тысяч ";
    else if (b == 9)
    cout << "Девять тысяч ";
    c = a / 100 % 10;
    if (c == 1)
    cout << "сто ";
    else if (c == 2)
    cout << "двести ";
    else if (c == 3)
    cout << "триста ";
    else if (c == 4)
    cout << "четыреста ";
    else if (c == 5)
    cout << "пятьсот ";
    else if (c == 6)
    cout << "шестьсот ";
    else if (c == 7)
    cout << "семьсот ";
    else if (c == 8)
    cout << "восемьсот ";
    else if (c == 9)
    cout << "девятьсот ";
    d = a / 10 % 10;
    if (d == 2)
    cout << "двадцать ";
    else if (d == 3)
    cout << "тридцать ";
    else if (d == 4)
    cout << "сорок ";
    else if (d == 5)
    cout << "пятьдесят ";
    else if (d == 6)
    cout << "шестьдесят ";
    else if (d == 7)
    cout << "семьдесят ";
    else if (d == 8)
    cout << "восемьдесят ";
    else if (d == 9)
    cout << "девяносто ";
    and = a % 10;
    if (d == 1)
    {
    if (e == 0)
    cout << "десять долларов";
    else if (e == 1)
    cout << "одиннадцать долларов";
    else if (e == 2)
    cout << "двенадцать долларов";
    else if (e == 3)
    cout << "тринадцать долларов";
    else if (e == 4)
    cout << "четырнадцать долларов";
    else if (e == 5)
    cout << "пятнадцать долларов";
    else if (e == 6)
    cout << "шестнадцать долларов";
    else if (e == 7)
    cout << "семнадцать долларов";
    else if (e == 8)
    cout << "восемнадцать долларов";
    else if (e == 9)
    cout << "девятнадцать долларов";
    }
    if (d != 1)
    {
    if (e == 0)
    cout << "долларов";
    else if (e == 1)
    cout << "один доллар";
    else if (e == 2)
    cout << "два доллара";
    else if (e == 3)
    cout << "три доллара";
    else if (e == 4)
    cout << "четыре доллара";
    else if (e == 5)
    cout << "пять долларов";
    else if (e == 6)
    cout << "шесть долларов";
    else if (e == 7)
    cout << "семь долларов";
    else if (e == 8)
    cout << "восем долларов";
    else if (e == 9)
    cout <= 100)
    {
    c = a / 100 % 10;
    if (c == 1)
    cout << "Сто ";
    else if (c == 2)
    cout << "Двести ";
    else if (c == 3)
    cout << "Триста ";
    else if (c == 4)
    cout << "Четыреста ";
    else if (c == 5)
    cout << "Пятьсот ";
    else if (c == 6)
    cout << "Шестьсот ";
    else if (c == 7)
    cout << "Семьсот ";
    else if (c == 8)
    cout << "Восемьсот ";
    else if (c == 9)
    cout << "Девятьсот ";
    d = a / 10 % 10;
    if (d == 2)
    cout << "двадцать ";
    else if (d == 3)
    cout << "тридцать ";
    else if (d == 4)
    cout << "сорок ";
    else if (d == 5)
    cout << "пятьдесят ";
    else if (d == 6)
    cout << "шестьдесят ";
    else if (d == 7)
    cout << "семьдесят ";
    else if (d == 8)
    cout << "восемьдесят ";
    else if (d == 9)
    cout << "девяносто ";
    and = a % 10;
    if (d == 1)
    {
    if (e == 0)
    cout << "десять долларов";
    else if (e == 1)
    cout << "одиннадцать долларов";
    else if (e == 2)
    cout << "двенадцать долларов";
    else if (e == 3)
    cout << "тринадцать долларов";
    else if (e == 4)
    cout << "четырнадцать долларов";
    else if (e == 5)
    cout << "пятнадцать долларов";
    else if (e == 6)
    cout << "шестнадцать долларов";
    else if (e == 7)
    cout << "семнадцать долларов";
    else if (e == 8)
    cout << "восемнадцать долларов";
    else if (e == 9)
    cout << "девятнадцать долларов";
    }
    if (d != 1)
    {
    if (e == 0)
    cout << "долларов";
    else if (e == 1)
    cout << "один доллар";
    else if (e == 2)
    cout << "два доллара";
    else if (e == 3)
    cout << "три доллара";
    else if (e == 4)
    cout << "четыре доллара";
    else if (e == 5)
    cout << "пять долларов";
    else if (e == 6)
    cout << "шесть долларов";
    else if (e == 7)
    cout << "семь долларов";
    else if (e == 8)
    cout << "восем долларов";
    else if (e == 9)
    cout <= 10)
    {
    d = a / 10 % 10;
    if (d == 2)
    cout << "Двадцать ";
    else if (d == 3)
    cout << "Тридцать ";
    else if (d == 4)
    cout << "Сорок ";
    else if (d == 5)
    cout << "Пятьдесят ";
    else if (d == 6)
    cout << "Шестьдесят ";
    else if (d == 7)
    cout << "Семьдесят ";
    else if (d == 8)
    cout << "Восемьдесят ";
    else if (d == 9)
    cout << "Девяносто ";
    and = a % 10;
    if (d == 1)
    {
    if (e == 0)
    cout << "Десять долларов";
    else if (e == 1)
    cout << "Одиннадцать долларов";
    else if (e == 2)
    cout << "Двенадцать долларов";
    else if (e == 3)
    cout << "Тринадцать долларов";
    else if (e == 4)
    cout << "Четырнадцать долларов";
    else if (e == 5)
    cout << "Пятнадцать долларов";
    else if (e == 6)
    cout << "Шестнадцать долларов";
    else if (e == 7)
    cout << "Семнадцать долларов";
    else if (e == 8)
    cout << "Восемнадцать долларов";
    else if (e == 9)
    cout << "Девятнадцать долларов";
    }
    if (d != 1)
    {
    if (e == 0)
    cout << "долларов";
    else if (e == 1)
    cout << "один доллар";
    else if (e == 2)
    cout << "два доллара";
    else if (e == 3)
    cout << "три доллара";
    else if (e == 4)
    cout << "четыре доллара";
    else if (e == 5)
    cout << "пять долларов";
    else if (e == 6)
    cout << "шесть долларов";
    else if (e == 7)
    cout << "семь долларов";
    else if (e == 8)
    cout << "восем долларов";
    else if (e == 9)
    cout < 0)
    {
    and = a % 10;
    if (e == 1)
    cout << "Один доллар";
    else if (e == 2)
    cout << "Два доллара";
    else if (e == 3)
    cout << "Три доллара";
    else if (e == 4)
    cout << "Четыре доллара";
    else if (e == 5)
    cout << "Пять долларов";
    else if (e == 6)
    cout << "Шесть долларов";
    else if (e == 7)
    cout << "Семь долларов";
    else if (e == 8)
    cout << "Восем долларов";
    else if (e == 9)
    cout << "Девять долларов";
    }
    else
    cout << "Ноль долларов";
    }
    else
    cout << "Вы ввели неверное число";

    return 0;
    }

  8. #include

    using namespace std;

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

    // Обявляем переменные целого типа
    int num, num_1, num_2, num_3;

    // Просим пользователя ввести числа
    cout <> num_1;
    cout <> num_2;
    cout << endl;
    // Просим пользователя ввести ответ
    cout << "Введите ответ "<< num_1 << " * " << num_2 <> num_3;
    cout << endl;
    // производим вычесления
    num = num_1 * num_2;

    //проверяем правильность ответа
    if(on one != num_3)

    {
    cout << "Вы ответили не правильно :(\n";
    cout << "Правильный ответ " << on one << endl;
    }
    else
    {
    cout << "Вы ответили правильно :)" << endl;

    }
    return 0;
    }

Leave a Reply

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