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. #include
    #include
    using namespace std;

    int main()
    {
    int nNum1, nNum2, nUserMultiply;

    cout <> nNum1;

    cout <> nNum2;

    cout <> nUserMultiply;

    if(nUserMultiply==(nNum1*nNum2))
    cout << "Ай, молодца! Действительно "
    << (nNum1*nNum2)
    << "!\n";
    else
    cout << "Ни фига подобного!\nИх произведение будет: "
    << (nNum1*nNum2)
    << "!\n";

    return 0;
    }

  2. #include
    #include
    using namespace std;

    int main(void)
    {
    setlocale(LC_ALL, "rus");

    int a(0), b(0), c(0);

    do {
    cout << a;
    } while (a >=10);

    do {
    cout << endl << b;
    } while (b >=10);

    cout << endl << "Введите произведение этих чисел:\t" << c;

    if (c == a * b) {
    cout << endl << "Вы ответили правильно!" << endl;
    }
    else cout << "Вы ответили неверно!" << endl << "Правильный ответ:\t" << (a*b);

    _getch();
    return 0;

    }

  3. Вот моя третья задача, с первой пока не складывается.
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, "rus");

    float enterNumber = 0;//первое число которое будет вводиться
    float interNumber = 0;//второе число которое будет вводиться
    float anterNumber = 0;// результат который введет пользователь

    cout << enterNumber;
    cout << interNumber;
    float itog=enterNumber+interNumber;// переменная подсчитает правильный итог

    {
    cout <<anterNumber;

    if (anterNumber==itog) cout << "Вы ввели верно ";//
    else if (anterNumber!= itog) cout << "вы ввели не верно, правильный результат = "<<itog;

    return 0;
    }
    }

  4. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL,"rus");

    int a;
    int b;
    int c;

    cout <<"Введите первое однозначное число: " <> a;
    cout <<"Введите второе однозначное число: " <> b;
    cout <<"Введите произведение чисел: " <> c;
    if (c!=a*b)
    {
    cout << "Произведение неверно! Вот что должно получиться: " << a*b;
    }

    if (c=a*b)
    {
    cout << "Абсолютно верно: " << a*b;
    }

    return 0;
    }

  5. Альтернативное решение второй задачки:

  6. int main()
    {
    setlocale(LC_ALL, "rus");

    int variable1 = 0;
    int variable2 = 0;
    int variable = 0;
    int otvet = 0;

    cout << variable1 >> variable2;

    cout << otvet;

    variable = variable1 * variable2;
    if (variable == otvet) cout << "Верно\n";
    else cout << "Правильный ответ = " << variable <9?

  7. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a = 0, b = 0, c = 0;

    cout << "Введите первое значение: " <> a;
    cout << "Введите второе значение: " <> b;
    cout << "Введите произведение введеныx чисел: " <> c;
    if (c==a*b)
    cout << "Ваш ответ верен " << endl;
    else cout << "Ваш ответ не верен, correct answer: " << a * b << endl;

    system("pause");
    return 0;
    }

  8. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a, b;
    cout <> a;
    cout <> b;
    if (a > 9 || b > 9)
    {
    cout <> a;
    cout <> b;
    }
    if (a < 0 || b < 0)
    {
    cout <> a;
    cin >> b;
    }
    cout <> c;
    d = a*b;
    while (d != c)// or if(d!=c), но тогда программа запросит результат еще 1 times
    {
    cout <> c;
    }
    if (d == c)
    cout << "молодец\n";
    system("pause");
    return 0;
    }

Leave a Reply

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