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. I think this is the best thing you can come up with

    #include (iostream)
    #include (ctime)
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “RU”);
    srand(time(NULL));
    int a = rand() % 10, b = rand() % 10, c;
    c = a * b;
    cout << "\t\t\t\t\t\tШкольные знания\n";

    cout << "Решите варажение: " << a << " * " << b

    <> a;
    if (a != c) {
    cout << "Ответ не верный!" << endl;
    }
    cout << "Правильный ответ = "<< c << endl;

    return 0;
    }

  2. #include
    using namespace std;

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

    cout << "Данное приложение проверяет ваше умение к умножению" << endl;
    cout << "” << endl;
    cout << "Введите два числа, the difference of which you want to guess" <> a;
    cin >> b;

    cout << "Введите предполагаемый ответ: " <> ans;

    real = a * b;

    if (real == ans) {
    cout << "Правильно! Answer: " << real;
    }
    else {
    cout << "Неправильно! Answer: " << real;
    }

    cout << endl << endl;

    return 0;
    }

  3. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int x,Y,from;
    cout <> x;
    cout <> Y;
    cout <> from;
    if ((x*y) == z)cout << "Верно!";
    else cout << "Не верно!" << endl;
    cout << "Правильный ответ: " << x * Y << endl;
    return 0;
    }

    1. #include
      using namespace std;
      int main()
      {
      setlocale(LC_ALL, “rus”);
      int x,Y,from;
      cout <> x;
      cout <> Y;
      cout <> from;
      if ((x*y) == z)cout << "Верно!";
      else if ((x*y) != z) cout << "Не верно! \nCorrect answer: " << x * Y << endl;

      return 0;
      }

  4. int a, b, c;
    std::cout << "Проверим таблицу умножения.\n";
    std::cout <> a;
    std::cin >> b;
    if (a == 0 || b == 0) {
    std::cout << "\nError..\n";
    return 0;
    }
    std::cout <> c;
    int summer = a * b;
    if (c == summer) {
    std::cout << "\nRight!\n";
    }
    else {
    std::cout << "\n[B]rror..\n";
    }

    1. #include
      using namespace std;
      int main() {
      setlocale(LC_ALL, “RU”);
      int a = 0;
      int b = 0;
      int z = 0;
      int x = 0;
      cout <> a;
      cout <> b;
      z = a * b;
      if (a >= 0 && a = 0 && b <= 9) {
      cout <> x;
      if (z == x) {
      cout << "Вы ответили правильно ";
      }
      else
      {
      cout << "Ваш ответ неправильный. "<< endl;
      while (from != x)
      {
      cout <> x; if (z == x) {
      cout << "Вы ответили правильно ";
      }
      }

      }
      }
      else
      {
      cout << "Значения не должны быть больше 9 или меньше 1";
      }
      return 0;
      }

  5. Your fucking “setlocale(LC_ALL, “RU”);” broke me all the symbols in the document itself and in the output to the terminal. How can I now return it to how it was?????g

  6. #include

    using namespace std;

    int main() {

    setlocale(LC_ALL, “RU”);

    int first_digit, second_digit, sumOfDigit, resultOfSum;

    cout <> first_digit;
    cout <> second_digit;

    sumOfDigit = first_digit * second_digit;

    cout <> resultOfSum;

    if (resultOfSum == sumOfDigit) {
    cout << " Right, result = " << sumOfDigit;
    }
    else {
    cout << "Неверно, your result = " << resultOfSum << " , and the correct answer = " << sumOfDigit;
    }

    return 0;
    }

  7. #include
    #include
    using namespace std;

    int main()
    {

    int num1;
    int num2;
    int yourChoice;

    cout <> num1;

    cout <> num2;

    int result = num1 * num2;

    cout <> yourChoice;

    if (yourChoice != result) {
    cout << "your were not correct, the result is " << result;
    } else {
    cout << "Correct!";
    }

    return 0;
    }

Leave a Reply

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