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. For this milky x find the value of the following function f, which takes the value of an integer type:

  2. Here is the code for the last task

    #include
    #include
    using namespace std;

    int main(int argc, char** argv) {
    setlocale(LC_ALL, “rus”);
    int a;
    int b;
    int c;
    int c1;
    cin >> a >> b;

    c = (a * b);

    cout << "Введите ответ выражения" <> c1;
    if(c == c1){
    cout << c << " correctly!!!" << endl;
    } else {
    cout << "не правильно вот правильный ответ "<< c << endl;
    }

    system("pause");
    return 0;
    }

  3. Hi, please tell me what other options are there by pressing a certain key to execute the code again. A task 3

    #include
    #include
    using namespace std;
    int main()
    {

    setlocale(LC_ALL, “rus”);
    int a, b;
    char R, c;
    int result;
    int resultP;
    link:
    cout << "Введите число а и б" <> a >> b;
    result = a * b;
    cout << "Введите результат" <> resultP;
    if (result == resultP)
    {
    cout << "Правильно!" << endl;
    }
    else
    cout << result << endl;
    cout << "Введите клавишу для рестарта" <> R;
    cin >> c;
    if (c == R)
    {

    goto link;
    }
    system(“pause”);

    return 0;
    }

  4. This option is suitable? Working code.

    #include
    using namespace std;
    int main(int argc, char** argv)
    {
    setlocale (LC_ALL, “russian”);
    char yes = 121;
    char no = 110;
    char e;
    int a, b, c, d;
    for (;;) // We go into an endless loop
    {
    cout <> a;
    cout << " \n";
    cout <> b;
    cout << "\n";
    d = a * b;
    cout <> c;

    if (c == d)
    {
    cout << " \n";
    cout << "Все правильно! \n";
    }

    else
    {
    cout << "Ошибка!!! \n";
    cout << "Правильный ответ :" << d << "\n";
    }
    cout <> e;
    cout << "\n";
    if (yes != e){ break; } // End the program by entering the character n
    }
    return 0;
    }

  5. Admin please delete the first message, not all the code is inserted.
    #include
    using namespace std;
    int main(int argc, char** argv)
    {
    setlocale (LC_ALL, “russian”);
    char yes = 121;
    char no = 110;
    char e;
    int a, b, c, d;
    for (;;) // We go into an endless loop
    {
    cout <> a;
    cout << " \n";
    cout <> b;
    cout << "\n";
    d = a * b;
    cout <> c;

    if (c == d)
    {
    cout << " \n";
    cout << "Все правильно! \n";
    }

    else
    {
    cout << "Ошибка!!! \n";
    cout << "Правильный ответ :" << d << "\n";
    }
    cout <> e;
    cout << "\n";
    if (yes != e){ break; } // End the program by entering the character n
    }
    return 0;
    }

  6. Yes, mom, why a piece of code is lost when you paste it on the site? I thought my jamb, but no.

  7. Here is the perfect code)
    #include
    #include
    using namespace std;
    int main(){
    int a,b,otvet,result;
    string vihod;
    do{
    cout<<"proverka na znanie tablice umnozeniya"<<endl;
    cout<<"введите первое число"<>a;
    cout<<"введите второе число"<>b;
    cout<<"введите ответ "<<endl;
    cout<>otvet;
    result=a*b;
    if (otvet == result){
    cout <<"Верно"<<endl;
    }
    else{
    cout<<"не верно а * b="<<result<<endl;
    }
    cout<<"ддя выхода напишите stop а для продолжения введите цифру"<>anger;
    }
    while(anger!=”stop”);
    cout <<"возвращайтесь к нам по позже)";
    return (0);
    }

Leave a Reply

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