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

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int number1 = 0;
    int number2 = 0;
    int number3 = 0;
    cout <> number1;
    cout <> number2;
    cout <> number3;
    if (number1 * number2 == number3) cout << "Вы правильно ввели ответ \n";
    else if (number1 * number2 != number3) cout << "Вы ввели неправильный ответ, The result is equal: " << number1 * number2 << endl;
    return 0;
    }

    Maybe someone will help ;)

    1. Do not write here in the comments your code!

      Commentary editor does not allow you to correctly enter C ++ code here, But the most important thing, what Nobody Your code is not needed here, nobody will not comment on him, Whether he is correct or wrong.

  2. The code transmits to the site with errors instead ” “wrote “-”
    #include -iostream-
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int number1 = 0;
    int number2 = 0;
    int number3 = 0;
    cout — “Enter the first factor: “;
    cin — number1;
    cout — “Enter the second factor: “;
    cin — number2;
    cout — “Enter the result of the work of previously introduced numbers: “;
    cin — number3;
    if (number1 * number2 == number3) cout — “You correctly introduced the answer n”;
    else if (number1 * number2 != number3) cout — “You introduced the wrong answer, The result is equal: ” << number1 * number2 << endl;
    return 0;
    }

  3. #include
    using namespace std;

    void main()
    {
    setlocale(LC_ALL, “Rus”);
    int a, b, c;
    cout <> a;
    cin >> b;
    cout <> c;
    if (c!=(a * b))
    {
    cout << "вы ответили не правильно !!!" << endl;
    cout << "правильный ответ – "<< a * b << endl;
    }
    else if (c==(a * b))
    {
    cout << "ваш ответ " << c << " Elongated" << endl;
    }
    }

  4. // Example program
    #include
    #include
    using namespace std;
    int main()
    {int a,b,c,f;
    cout<>a;
    cin>>b;
    c= a*b;
    cout<>f;
    if (f==c) cout<<"verno";
    else if(f!=c) cout<<"ne verno , "<<"verno = "<<c;
    return 0 ;
    }

    1. In general, your lessons are insanely cool!
      I am preparing for the program of programming at the university in your lessons-everything is clarified very well and understandable, Special thanks for the video

    2. Perhaps…
      But only this page is dedicated and called: “Select if and else statements in c ++”.
      And relative to Switch there are other pages.

  5. #include “stdafx.h”
    #include

    using namespace std;

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

    int c1(0);
    int c2(0);
    int c(0);

    cout << "Введите первое число " <> c1;
    cout << "Введите второе число " <> c2;
    cout << endl << endl << endl << endl;

    cout << "Введите ответ: " <> c;

    if (c1 * c2 == c)
    cout << "Поздравляем! Correct answer" << endl;
    else
    {
    cout << "Ошибка!!!!!!!!!!!!!!!!!!!" << endl;
    cout << "Правильный ответ: " << c1 * c2 << endl;
    }
    return 0;
    }

    The last task)

Leave a Reply

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