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. for (;;)
    {
    system(“cls”);
    int x, Y, answer, result;

    cout <> x;

    cout <> Y;

    cout <> answer;

    result = x * Y;

    if (result == answer)
    cout << "\n\nОтвет верный: " << answer;
    else
    cout << "\n\nОтвет неверный. Ваш ответ: " << answer << " Correct answer: " << result;
    Sleep(10000);
    }

  2. #include “stdafx.h”
    #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “russian”);
    int a, b, c, d;
    cout << "Введите два числа" << endl;
    cout <> a;
    cout <> b;
    cout << "Введите результат умножения c=a*b?" << endl;
    c = a * b;
    cout <> d;
    if (c == d)
    {
    cout << "Вы ответили правильно" << endl;
    }
    else
    {
    cout << "Вы ответили неверно, correct answer: " << c << endl;
    }
    system("pause");
    return 0;
    }

  3. #include “stdafx.h”
    #include “pch.h” // НА МОЕМ КОМПЕ БЕЗ ЭТОГО НЕ РАБОТАЕТ
    #include
    #include // ЧИСЛА ГЕНЕРИРУЮТСЯ САМИ
    using namespace std;

    int main()
    {
    srand(time(0));
    int x, Y,result,answer;
    for (int i = 0; i < 50; i ) {
    x = 1+rand() % 10;
    y = 1+rand() % 10;
    result = x * Y;
    cout << x << "*" << Y << "=?" <> answer;
    if (answer == result)
    cout << "Yes" << endl << endl;
    else cout << "No, result is " << result << endl << endl;

    }

    }

    1. там скобки не работают, поэтому там сверху #include iostream и ниже #include ctime.

  4. #include “pch.h”
    #include
    #include
    #include

    using namespace std;

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

    int num_1 = 0;
    int num_2 = 0;
    int userProduct = 0;

    cout << " Use only single digits!!! " << endl;
    cout << " Enter Num 1 : " <> num_1;
    cout << " Enter Num 2 : " <> num_2;
    if (num_1 9 || num_2 9) {
    cout << " This number does not meeet the requirements " << endl;
    }
    else {
    cout << " 'Num 1' * 'Num 2' = " <> userProduct;
    if (userProduct == num_1 * num_2) {
    cout << " You right!!! " << endl;
    cout << num_1 << " * " << num_2 << " = " << userProduct << " ! ";
    }
    else {
    cout << " Wrong !!! " << endl;
    cout << num_1 << " * " << num_2 << " = " << num_1 * num_2 << " ! ";
    }
    }
    }

  5. #include

    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a;
    int b;
    cout<<"Введите два целых однозначных числа"<<endl;
    cout<>a;
    cout<>b;
    float result;
    bool p = true;
    while(p){
    if(a>9 || b>9){
    cout<<"Вы ввели некорректную сумму, повторите ввод"<<endl;
    cout<>a;
    cout<>b;
    p=true;
    }
    else{p=false;}
    }
    float answer = a*b;
    cout<>result;
    if(result==answer){
    cout<<"Ответ верный";
    }
    else{
    cout<<"Ответ неверный, correct answer: "<<answer;
    }

    return 0;
    }

  6. Вы что там курите? или просто больные все на голову, ну не реально решить 1 задание если знакомы только арифметические действия, лечитесь….. Ваш сайт вызывает ассоциации

  7. Decision 3 tasks.
    с++ код:
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “ru”);
    cout << "Введи первый множитель: " <> on one;
    cout << "Введи второй множитель: " <> num2;
    cout << "Введи ответ умножения первого на второе: " <> result;
    if (result == (num*num2)) {
    cout << "Правильно!" << endl;
    }
    else {
    cout << "Ошибка! " << on one << " * " << num2 << " = " << on one * num2 << endl;
    }
    return 0;
    }

  8. // Выслушаю замечания по коду. Учусь на этом сайте вместе с остальными.

    #include
    using namespace std;

    int main(int argc, char const *argv[])
    {
    setlocale(LC_ALL, “Russian”);
    cout <> a;
    cout <> b;
    if (a >= 0 && a = 0 && b <= 9)
    {
    cout <> c;
    int result = a * b;
    if (result == c)
    {
    cout << "Правильно!" << endl;
    }
    else
    {
    cout << "Неправильно!" << " 1-е число умножить на 2-е = " << result;
    }
    }
    else
    {
    cout << "Требуется ввод только однозначных чисел!";
    }

    return 0;
    }

Leave a Reply

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