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. Решение задачи №3

    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “”);
    int x;
    int y;
    int res;

    cout << "Введите первое число: " <> x;
    cout << "Введите второе число: " <> Y;
    cout << "Введите произведение двух чисел: " <> res;

    if (res == x * Y){
    cout << "Ответ правильный" << endl;
    }
    else
    {
    cout << "Ответ неправильный" << endl << "Правильный ответ: " << x*y << endl;
    }
    system("pause");
    return 0;
    }

  2. #include
    #include
    using namespace std;

    int main(int argc, char** argv) {
    setlocale(LC_ALL, “rus”);
    int a;
    int b;
    int c;
    int c1;
    cin >> a >> b;

    c = (a * b);

    cout << "Введите ответ выражения" c1;
    if(c == c1){
    cout << c << " correctly!!!" << endl;
    } else {
    cout << "не правильно вот правильный ответ "<< c << endl;
    }

    system("pause");
    return 0;
    }
    Pashok, оно не работает.
    Вот этот работает на "аря".
    #include

    using namespace std;

    int main()
    {
    int a = 0;
    int b = 0;
    int c = 0;
    int c1 = 0;

    cout<<"Проверяем знание пользователем ТАБЛИЦЫ УМНОЖЕНИЯ. Let's go!"<<endl;

    cout<> a;
    cout <> b;
    cout<>c;

    c1 = (a * b);

    if(c == c1)
    {
    cout << c << " correctly!!!" << endl;
    }
    else if (c!=c1)
    {
    cout << "не правильно, вот правильный ответ "<< c1 << endl;
    }
    return 0;
    }

  3. Принимайте 3.

    #include “pch.h”
    #include

    using namespace std;
    int main() {

    setlocale(0, “”);
    int x, Y, result, answer;
    cout << "\t\t Проверим твоё знание таблицы умножения" << endl << endl;

    cout <> x;
    if (x >= 10 || x < 1)
    cout << "В условии сказано ввести число от 1 to 9 ";
    else
    {
    cout <> Y;
    if (Y >= 10 || Y < 1)
    cout << "В условии сказано ввести число от 1 to 9 ";
    else
    {
    cout <> answer;
    result = x * Y;
    if (result == answer)
    cout << "Да! Right! Таблицу умножения ты знаешь хорошо! ";
    else
    {
    cout << "К сожалению ответ не верный" << endl << "Правильный ответ – " << result;
    }
    }
    }

    return 0;
    }

  4. решение задачи №3

    #include
    using namespace std;
    int main()
    {
    setlocale(0, “”);
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    cout << "Введите первое число:" <> a;
    cout << "Введите второе число:" <> b;
    cout << "Введите ответ:" <> d;
    c = a*b;
    if (c == d) cout <<"ответ \t"<< c <<"\t верный:"<< endl;
    else if (c != d) cout << "ответ неверный. Correct answer: " << c << endl;
    system("pause");
    return 0;
    }

  5. int main()
    {
    int a,b,umn, umn_ver;
    cout << "vvedite pervoe chislo:" <> a;
    cout << "vvedite vtoroe chislo:" <> b;
    umn_ver = a * b;
    cout << "vvedite rezultat umozheniya etih chisel:" <> umn;
    if (umn == umn_ver)
    cout << "Pravilno!";
    else cout << "Neverno! \n" << "Pravilniy otvet =" << umn_ver << endl;
    return 0;

    }

  6. #include
    #include

    using namespace std;

    void main() {
    double x, Y, res;
    cout <> “; cin >> x;
    cout <> “; cin >> Y;

    do {
    cout <>”; cin >> res;
    if (res == x * Y)
    cout << "true";
    else {
    cout << "falce";
    }
    } while (res != x * Y);
    system("pause");
    }

  7. 3-I task
    #include
    int main() {
    setlocale(LC_ALL, “rus”);
    int p;
    std::cout <> a >> b;
    std::cout <> p;
    if (a * b == p) {
    std::cout << "Ответ правильный";
    }
    else if (a * b != p){
    std::cout << "Ответ неверный!";
    }
    return 0;
    }

  8. Вот задача номер 3.

    #include “pch.h” // необходимо для корректной отладки в Visual Studio
    #include

    using namespace std;

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

    int a, b, res;
    cout << "Первое число: " <> a;
    cout << "Второе число: " <> b;

    cout << "Сколько будет: " << a << " * " << b << " = " <> res;

    if (a * b == res) {
    cout << "Да, ты прав."<<endl;
    }
    else {
    cout << "Нет, you're wrong. Вот тебе правильный ответ: " << a * b;
    }
    system("pause");
    return 0;
    }

Leave a Reply

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