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. Hope, 3 so the problem is solved, well, or at least, it seems)

  2. #include “stdafx.h”
    #include
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    srand(time(0));
    int UM = 0;
    int UK = 0;
    int answer;
    cout << "\t\t<>\n”;
    cout << (UM = rand() % 10) << " * " << (UK = rand()% 10) <> answer;
    if (answer == (ONE * UK))
    {
    cout << "Верно." << endl;
    }
    else
    {
    cout << "Неверно. Answer " << (ONE * UK) << endl;
    }

    return 0;
    }

  3. Somebody went to solve 1 the task?

  4. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a, b, r;
    cout << "Введи два числа: " <> a;
    cin >> b;
    cout <> r;
    if (r == a*b) cout << "Правильно!" << endl << endl;
    else cout << "Не правильно! Answer: " << (r = a*b) << endl << endl;
    system("pause");
    }

    Answer to 3 the task, It seems to be correct.

    1. <#include
      using namespace std;
      int main()
      {
      setlocale(LC_ALL, “rus”);
      int a, b, r;
      cout << "Введи два числа: " <> a;
      cin >> b;
      cout <> r;
      if (r == a*b) cout << "Правильно!" << endl << endl;
      else cout << "Не правильно! Answer: " << (r = a*b) << endl <

      In the code, an error occurred while sending.

  5. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a, b,res;
    cout <> a;
    cout <> b;
    cout <> res;
    if (res == a*b)
    {
    cout << "ПРАВИЛЬНО !!!You know Table. multiplication!!!!" << endl;
    }
    else
    {
    cout << "Вы не знаете табл. multiplication!!! и правильный ответ = "<<a * b<<endl;

    }
    return 0;
    }

  6. Second, you can do so:

    #include
    using namespace std;

    int main()
    {
    int a;

    setlocale(LC_ALL, “rus”);

    cout <> a;

    if (a 10)
    cout << "Данный палец у нас отсуствует :)" << endl;
    else cout << "Вы ввели цифру которая не привышает 10 and not less than 1. This means that, " << endl;

    if (a == 1) cout << "Вы ввели мезинец" << endl;
    if (a == 2) cout << "Вы ввели безымянный палец" << endl;
    if (a == 3) cout << "Вы ввели среднии палец" << endl;
    if (a == 4) cout << "Вы ввели указательный палец" << endl;
    if (a == 5) cout << "Вы ввели большой палец" << endl;
    if (a == 6) cout << "Вы ввели большой палец" << endl;
    if (a == 7) cout << "Вы ввели указательный палец" << endl;
    if (a == 8) cout << "Вы ввели среднии палец" << endl;
    if (a == 9) cout << "Вы ввели безымянный палец" << endl;
    if (a == 10) cout << "Вы ввели мезинец" << endl;
    system("pause");
    }

    1. #include
      using namespace std;

      int main()
      {
      int a;

      setlocale(LC_ALL, “rus”);

      cin>>a;

      if (a==10)
      cout << "Äàííûé ïàëåö ó íàñ îòñóñòâóåò :)" << endl;
      else cout << "Âû ââåëè öèôðó êîòîðàÿ íå ïðèâûøàåò 10 è íå ìåíüøå 1. To ýòî çíà÷èò ÷òî, " << endl;

      if (a == 1) cout << "Âû ââåëè ìåçèíåö" << endl;
      if (a == 2) cout << "Âû ââåëè áåçûìÿííûé ïàëåö" << endl;
      if (a == 3) cout << "Âû ââåëè ñðåäíèè ïàëåö" << endl;
      if (a == 4) cout << "Âû ââåëè óêàçàòåëüíûé ïàëåö" << endl;
      if (a == 5) cout << "Âû ââåëè áîëüøîé ïàëåö" << endl;
      if (a == 6) cout << "Âû ââåëè áîëüøîé ïàëåö" << endl;
      if (a == 7) cout << "Âû ââåëè óêàçàòåëüíûé ïàëåö" << endl;
      if (a == 8) cout << "Âû ââåëè ñðåäíèè ïàëåö" << endl;
      if (a == 9) cout << "Âû ââåëè áåçûìÿííûé ïàëåö" << endl;
      if (a == 10) cout << "Âû ââåëè ìåçèíåö" << endl;
      return 0;
      }
      you had a mistake,I have corrected

  7. int main()
    {
    int a, b, c, d;
    cout << "======================================================" << endl <> a >> b;
    cout << "======================================================" <= -9 && b >= -9 && a <= 9 && b =-9 && b>=-9 && a<=9 && b<=9 ) {
    cout <> c;
    cout << "======================================================"<<endl;
    d = a*b;

    c == d ? cout << "Pravilno!" << endl << "======================================================" << endl : cout << "Nepravilno! " << a << " * " << b << " = " << d << endl << "======================================================" << endl;
    }
    else {
    cout << "Eto ne zeloe odnoznachnoe chislo!" << endl<< "======================================================" << endl;
    system("pause");
    exit(0);
    }

    system("pause");
    return 0;
    }

Leave a Reply

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