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.

370 thoughts on “Tasks: Select if and else statements in c ++

  1. Thanks for the assignments. Started doing the task (about 0-9999) and now I'm stuck on data entry checks – I want to do everything beautifully at once)

    Did it intuitively, I played around and it seems to work fine.
    Can you explain in detail?, what exactly do these commands do or provide links about flows with a clear explanation (I checked what they output, looked at the differences, etc.).
    Namely: cin.clear(); cin.ignore();in_avail();cin.get();cin.fail(). and what can be written inside the brackets? And further “->” – it's also not entirely clear(what it returns is something like, but here's how it works?)

  2. Here is:

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

  4. For some reason, when displaying a truthful answer, it appears twice (problem without answer – 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. You need to put it in curly braces
      else {
      cout << "You are mistaken :" << endl; cout << a << " * " << b << " = " << d << endl; }

    1. It is necessary to write a program to check if the entered number is not in the range from – 5 to – 1. Will you help?? C

  5. task 3 I decided so:

  6. When I fixed all the errors the program worked the first time.
    If anyone has problems solving the 3rd problem, here is an example of my code:

Leave a Reply

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