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. Спасибо за задания. Начал делать задачу (про 0-9999) и вот заткнулся на проверки ввода данныххочется все сразу красиво сделать)

    Делал это интуитивно, баловался и вроде работает нормально.
    Можете подробно объяснить, что конкретно делают эти команды или кинуть ссылки про потоки с внятным объяснением (проверял что они выводят, смотрел на различия и т.д.).
    Namely: cin.clear(); cin.ignore();in_avail();cin.get();cin.fail(). и что можно писать внутри скобок? And further “->” – тоже не совсем понятно(то что он возвращает что то вроде, но вот как он работает?)

  2. Here is:

  3. int n;
    bool success = false;
    while (success == false)
    {
    cout <> n;
    if ((n >= 0) && (n in_avail()) == 1)
    {
    cout <in_avail()); //удаляем символы в буфере
    }
    else
    {
    cout << "\nВ вашем числе присутсвуют едопустимые символы.\nПопробуйте еще раз." <in_avail()); //удаляем символы в буфере
    }
    }

  4. Почему-то при выводе правдивого ответа он вылазит дважды (задача без ответа – code):

    #include
    #include

    using namespace std;

    int main() {
    int a, b, c, d;

    cout << "Enter a" <> a;
    cout << "Enter b" <> b;
    cout << a << " * " << b << " = " << "result" << endl;
    cout << "Enter result :" <> c;
    d = a * b;

    if(c == a * b) {
    cout << "You're right :" << endl;
    cout << a << " * " << b << " = " << d << endl;
    } else
    cout << "You are mistaken :" << endl;
    cout << a << " * " << b << " = " << d << endl;

    cin.get();
    return 0;
    }

    1. Надо взять в фигурные скобки
      else {
      cout << "You are mistaken :" << endl; cout << a << " * " << b << " = " << d << endl; }

  5. А то, что юзер должен ввести ОДНОЗНАЧНЫЕ ЧИСЛА никого не смущает? Все просто мимо эту проверку пропускают.

    1. Необходимо написать программу проверки не вхождения введенного числа в диапазоне от – 5 to – 1. Поможете? C

  6. Задачу 3 я решил так:

  7. Почему я не могу посмотреть код к второму заданию?

  8. Когда исправил все ошибки прога заработала с первого раза.
    Если у кого-то возникают проблемы с решением 3-ей задачи вот пример моего кода:

Leave a Reply

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