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. Exist 3 заданием справился таким кодом:
    #include
    using namespace std;
    int main ()
    {

    int a,b,c,summ;

    cin»a;
    cin»b;
    if (a>=1 && a=1 && b<=9)
    {

    summ=a*b;
    cout«"Введите ответ! : "«endl;
    cin»c;
    if (c==summ)
    {
    cout«"Верно!"«endl;
    } else {cout«"Вот верный ответ : "«summ;}
    }
    }

    1. #include
      using namespace std;
      int main ()
      {

      int a,b,c,summ;

      cin>>a;
      cin>>b;
      if (a>=1 && a=1 && b<=9)
      {

      summ=a*b;
      cout<<"Введите ответ! : "<>c;
      if (c==summ)
      {
      cout<<"Верно!"<<endl;
      } else {cout<<"Вот верный ответ : "<<summ;}
      }
      }

  2. #include
    #include

    using namespace std;
    int main()
    {
    short FirstChar;
    short SecondChar;
    short Answer;
    cout << "Ведите два чила" <> FirstChar >> SecondChar;
    cout << "Сколько будет " << FirstChar << " Умножить на " << SecondChar << "?" <> Answer;
    if (Answer == FirstChar * SecondChar){
    cout << "Верно! This number: " << Answer;
    } else {
    cout << "Неверно! Correct answer: " << FirstChar * SecondChar << endl;
    }
    return 0;
    }

    1. Не пишите сюда свои попытки с экспериментированием с кодом. Это никому не нужно! (и никто не станет это смотреть).

      Comments are not for!

      1. Кто не справляется — задавайте вопросы в комментариях. разве не так пишет под заданием?

      2. Так написано жекто не справляется“, but not “кто справляется“? — почувствуйте разницу.
        И написаноask questions in the comments“, но не написано жетулите в комментарии свой код“.

        And, finally, редактор сайта искажает код C++, поэтому его просто бессмысленно сюда писать, и смотреть это никто не станет.

  3. не пойму решения первой задачи. я ее решил, но код получился просто огромным, раза в два больше этого. почему в вашем коде, при вводе 4-х значного числа, при первом же правильном (true) ответе, операция не заканчивается и он не выдает просто “Две тысячи”, or “Девять тысяч”?

  4. #include

    using namespace std;

    int main()
    { int a,b,much,value;
    cout<<"enter two values"<>a>>b;
    mult=a*b;
    cout<<"enter your value"<>value;
    if (mult==value)
    cout<<"well-done";
    else if(much!=value)
    cout<<"you are wrong"<<much;

    return 0;
    }

      1. А нельзя комментарии удалять?Я на счет кода!Если кто-то будет не цензурно выражаться-это же как-то удаляется?

      2. Ему наверное это не нужно.Но было-бы здорово,если бы комментарии несли только полезную информацию,много есть в них того,что дополняет сайт!

  5. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a;
    cout <> a;
    int b;
    cout <> b;
    int c = a*b;
    int d;
    cout <> d;
    if (c == d)
    cout << "Правильный ответ!\n";
    else
    cout << "Вам еще надо поучится считать!\n";
    system("pause");
    }

  6. Вот так я решил третью задачу:

    1. Упс, что-то тут не правильно вывелось, поэтому напишу обычным способом:
      #include
      using namespace std;

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

      int num1 = 0;
      int num2 = 0;
      int otvet = 0;

      cout << "СЕЙЧАС МЫ ПРОВЕРИМ ВАС НА ЗНАНИЕ МАТЕМАТИКИ\n";
      cout <> num1;
      cout <> num2;

      cout <> otvet;

      if ((num1 * num2) == otvet) {
      cout <<"Вы правы, вот ход решения "<< num1<< " * " << num2 << " = " << otvet;
      } else {
      cout <<"Упс";
      }

      return 0;
      }

      1. Читай внимательно комментарии!Неужели не догоняете??Напиши еще код:всем будет интересно,как ты необычно и по простому написал такую сложную задачу

  7. f(x)=((sqrt(1.7*x+sin(x)^1/3 если 0<x<=2;
    cos(pi*x)+tgx если 2<x<=6 как решить задачу с помощью с++, Help

Leave a Reply

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