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() {
    setlocale(LC_ALL, “RU”);

    int a;
    int b;
    int res;
    int d;

    cout <> a;
    cout <> b;
    cout <> res;
    d = a * b;
    cout << "проверочный результат\n" << d << endl;

    if (nothing == d) {
    cout << "Ответ верный\n";
    }
    else
    cout << "Сработал неверно\n" << endl;
    if (res!=d)
    cout << "Правильный ответ\n" << d << endl;

    return 0;

    }

  2. #include ;
    using namespace std;
    int main() {
    setlocale(LC_ALL, “ru”);
    bool i = true;
    int num1;
    int num2;
    long res;
    long choose;
    for (i; i = true;) {
    cout << "Введите два однозначных числа через пробел" <> num1 >> num2;
    res = { num1 * num2 };
    cout <> choose;
    cout << endl;
    if (choose != res) {
    cout << "Вы ввели неверное значение! Еще раз" << "\n";
    }
    else if (choose == res) {
    cout << "Вы угадали!" << endl;
    i = false;
    break;
    }
    }
    cout << "Вы вышли " << endl;
    system("pause");
    return 0;
    }

  3. #include
    #include

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

    int a, b, user_result, result;
    cout <> a;
    if (a < 0) {
    cout << "До отрицательных умножений ты еще не дорос 8р";
    cout << " " << endl << " " << endl << " " < 9) {
    cout << "Я ж сказал цифру, and not the number! Иди отсюда, балбес!" << endl;
    cout << " " << endl << " " << endl << " " << endl;
    return 0;
    }
    cout << "Что там у тебя за вторая цифра? " <> b;
    if (b < 0) {
    cout << "До отрицательных умножений ты еще не дорос 8р" < 9) {
    cout << "Я ж сказал цифру, and not the number! Иди отсюда, балбес!" << endl;
    cout << " " << endl << " " << endl << " " << endl;
    }
    cout << "А перемножить их если, сколько получится? " <> user_result;
    result = a * b;
    if (user_result == result) {
    cout << " " << endl << " " << endl << " " << endl;
    cout << "Угадал, хороняка!";
    }
    else if (user_result < 0) {
    cout << " " << endl << " " << endl << " " << endl;
    cout << "Ты что, обалдел совсем? ";
    }
    else cout << "Не угадал, иди учи таблицу умножения! ";

    cout << " " << endl << " " << endl << " " << endl;

    return 0;
    }

  4. #include
    using namespace std;

    int main()
    {

    setlocale(0, “”);

    int number1 = 0;
    cout <> number1;
    int number2 = 0;
    cout <> number2;
    int resultuser = 0;
    int result = number1 * number2 ;
    if (number1 <= 10 && number2 0 && number2>0) {
    cout <> resultuser;

    }
    else {
    cout << "\nВведите число(-and) из таблицы умножения или положительное число.\n";
    }
    if (resultuser == result) {
    cout << "Всё верно, well done!";
    }
    else {
    cout << "Нет, неверно! Correct answer:";
    cout << result;
    }

    return 0;

    };

  5. #include

    using namespace std;

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

    int numberFirst{};
    cout <> numberFirst;

    int numberSecond{};
    cout <> numberSecond;

    cout << "\nyour two numbers: " << numberFirst << " , " << numberSecond << endl;

    cout << "The result of multiplying the first number by the second? " << numberFirst << " * " << numberSecond <> result;
    if (result == (numberFirst * numberSecond))
    {
    cout << "\n you answered correctly! Doing Great! " << endl;
    }
    else
    {
    cout << "\nyou answered incorrectly =( " << endl << "correctrly answered = " << numberFirst * numberSecond << endl;
    }
    }

  6. ответ на первую задачку, принимает любое число

    #include
    void vvod(int su)
    {
    int ost = su % 10;
    if (ost == 1)
    {
    std::cout << are < 1 && ost < 5)
    {
    std::cout << are << " доллара";
    }
    else
    {
    std::cout << are <> sum;
    vvod(sum);
    return 0;
    }

    1. почему то неправильно скопироваось

      #include

      void vvod(int su)
      {
      int ost = su % 10;
      if (ost == 1)
      {
      std::cout << are < 1 && ost < 5)
      {
      std::cout << are << " доллара";
      }
      else
      {
      std::cout << are <> sum;
      vvod(sum);
      return 0;
      }

Leave a Reply

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