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. // A task: “Multiplication table”
    #include “stdafx.h”
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a, b, c, d;
    cout <> a;
    cout <> b;
    c = a * b;
    cout <> d;
    if (d != c) {
    cout << "Неверно, the result of multiplying the first day of the second: " << c << endl;
    }
    else
    cout << "Верно, the result of multiplying the first day of the second: " << c << endl;

    system("pause");
    return 0;
    }

  2. #include
    #include
    using namespace std;

    int main()
    {
    int mnozitel1, mnozitel2, proizvedeniye, otvet;
    setlocale(LC_ALL, “Russian”);
    cout << "Введите первый множитель" <> mnozitel1;
    cout << "Введите второй множитель" <> mnozitel2;
    proizvedeniye = mnozitel1 * mnozitel2;
    cout << "Введите произведение" <> otvet;
    if (otvet == proizvedeniye)
    {
    cout << "Ваш ответ верный" << endl;
    }
    else
    {
    cout << "Ваш ответ не верный" << endl;
    }
    system("pause");

    }

  3. #include

    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int iMn1=0;
    int iMn2 = 0;
    int iRez1=0;
    int iRez2 = 0;

    cout <> iMn1;
    cout <> iMn2;
    cout <> iRez1;

    iRez2 = iMn1 * iMn2;
    if (iRez1 == iRez2) cout << "Вы правы ";
    else cout << "Вы ошиблись правильный результат= " << iRez2 ;

    return 0;
    }
    As it so happened.

  4. #include
    using namespace std;

    int main(){
    int a,b,result,userresult;
    cin>>a>>b;
    cout<>userresult;
    result=a*b;
    if(result==userresult){
    cout<<"Otvet Veren";
    }else if(result!=userresult){
    cout<<"Vi Oshiblis";
    }
    }

  5. #include “stdafx.h”
    #include “iostream”
    #include “windows.h”
    using namespace std;

    int main()
    {
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    int x, Y;
    int prod1;
    cout << "Давайте проверим ваше знание таблицы умножения! Программа повторится 5 раз." << endl;
    for (int i = 0; i < 5; i ) {
    cout << "Введите два числа: " <> x >> Y;
    prod1 = x*y;
    int prod2;
    if (x > 0 && x 0 && Y < 10) {
    cout << "Введите результат умножения этих двух чисел: " <> prod2;
    if (prod1 == prod2)
    cout << "Вы молодец!" << endl;
    else if (prod1 != prod2)
    cout << "Вы ошиблись, correct answer: " << prod1<<endl;
    }
    else
    cout << "Вы ввели неверные числа." << endl;
    }
    system("pause");
    return 0;
    }

  6. #include
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int number1 = 0, number2 = 0, answer = 0;
    answer:
    std::cout << "\nТаблица умножения\n\n";
    std::cout <> number1;
    std::cout <> number2;
    std::cout << "Сколько будет " << number1 << " on " << number2 <> answer;
    if((number1*number2) == answer)
    std::cout << "Точно! ";
    else
    std::cout << "нет! Correct answer " << number1 * number2;

    std::cout << std::endl;
    goto answer;
    return 0;
    }

    1. 1000000 раз уже здесь в комментариях писали: Do not write your code here!
      1. редактор здесь в комментариях не позволяет корректно изобразить C++ код.
      2. ваш код здесь никому и нафиг не нужендля чего вы его сюда все пишете?

  7. #include
    using namespace std;

    int a; // First number
    int b; // The second number
    int c; // Верное произведение
    int d; // Вариант пользователя

    int main()
    {
    setlocale(LC_ALL, “rus”);
    cout << "Введите любые два однозначных числа" <> a; // Знаю, что можно прописать cin >> a >> b;
    cin >> b;
    cout << "Отлично! Теперь напиши свой результат" <> d;

    if (d == c)
    cout << "Правильно!" << endl;
    else
    cout << "Неправильно! Верный результат" << "c" << "а твой" << "d" << endl;

    system("pause");
    return 0;
    }

Leave a Reply

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