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. #include
    using namespace std;
    int main()
    {setlocale(LC_ALL, “rus”);
    cout << " А сейчас мы проверим твое знание таблицы умножения!:-)" << endl;
    int a, b, c;
    do {
    cout <> a;
    cout <> b;
    if( b == 0){
    cout << "Ошибочка вышла;-)" << endl;
    break;
    }
    cout <> c;

    if (c == a*b){
    cout << "Это правильный ответ!"<< endl;
    } else{
    if (b!=0){
    cout << "Ответ неверен!:-P Правильный ответ: " << a * b << endl;
    }
    } cout << "Для выхода из программы произведите умножение на ноль!" << endl;
    } while (b);
    cout << "На ноль умножать нельзя, поэтому выйдем из программы!:-P" << endl;
    return 0;

    }

  2. #include
    #include
    using namespace std;
    int main(){
    setlocale(LC_ALL, “rus”);

    cout << "Проверим ваше знание таблицы умножения" << endl;
    int a , b , c;
    cout <> a;
    cout << endl <> b;
    int first_x = a;
    int second_x = b;
    cout << "Сколько будет " << first_x << " * " << second_x << "?" <> c;
    if (c == a * b){
    cout << "Ответ " << c << " верен!" << endl;
    }
    else if (cout << "Ответ не верен, correct answer : " << a * b << endl);

    system("Pause");

    }

  3. First task

    #include
    #include
    using namespace std;
    int main(){
    setlocale(LC_ALL, “rus”);
    int a1 = 0;
    int b1 = 0;
    cout << "Введите переменую " <> A1;
    b1 = a1 % 10;
    if (b1 == 1)
    cout << "Ваша сумма – " << A1 << " долар" << endl;
    else if ((b1 == 2) || (b1 == 3) || (b1 == 4))
    cout << "Ваша сумма – " << A1 << " долара" << endl;
    else((b1 == 5) || (b1 == 6) || (b1 == 7) || (b1 == 8) || (b1 == 9) || (b1 == 0));
    cout << "Ваша сумма – " << A1 << " доларов" << endl;
    return 0;
    }

  4. Задача про пальцы

    #include
    #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a1= 0;
    cout <> A1;
    if ((a1 == 1) || (a1 == 10))
    {
    cout << "Это большой палец \n";
    }
    else if ((a1 == 2) || (a1 == 9))
    {
    cout << "Это указательный палец \n";
    }
    else if ((a1 == 3) || (a1 == 8))
    {
    cout << "Это средний палец \n";
    }
    else if ((a1 == 4) || (a1 == 7)) {
    cout << "Это безыимяный палец \n";
    }
    else if ((a1 == 5) || (a1 == 6)) {
    cout <= 11)||(A1<=0))
    {
    cout << "Такого пальца нет \n";
    }
    return 0;
    }

  5. #include

    using namespace std;

    int main() {

    setlocale(LC_ALL, “”);

    int num1;
    int num2;
    int answer;

    cout <> num1;

    cout <> num2;

    cout << "Напишите ответ данного примера: " << num1 << " * " << num2 <> answer;

    if ( answer == num1*num2 ) {
    cout << "Вы ответили правильно!";
    } else if ( answer != num1*num2 ) {
    cout << "Вы ответили не правильно!";
    cout << " Correct answer: " << num1 << " * " << num2 << " = " << num1*num2;
    }

    return 0;

    }

  6. #include
    using namespace std;

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

    int a, b, c;

    cout << "!!Проверим таблицу умножения!!" << endl;
    cout <> a;
    cout <> b;

    cout <> c;

    if (c == a * b) {
    cout << "Ваш ответ: " << c << " Правильный!";}
    else {
    cout << "Ваш ответ: " << c << " Неправильный" << endl;
    cout << "Правильный ответ: " << a * b;
    }
    }

  7. ссылка на код так как не отображает коректно cpp.sh/3ya3u

  8. #include
    using namespace std;
    int main()
    {
    int a, b, d, r;
    cout <> a;
    cout <> b;
    r = a * b;
    if (r>=100)
    cout << "Errors. Enter numbers 1-10.";
    else {
    cout <> d;
    if (d == r)
    cout << "True.";
    else
    cout << "False. Try again. Answer: " << r;
    }
    return 0;
    }

Leave a Reply

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