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.

370 thoughts on “Tasks: Select if and else statements in c ++

  1. Exist 3 I completed the task with this code:
    #include
    using namespace std;
    int main ()
    {

    int a,b,c,summ;

    eating;
    eat" b;
    if (a>=1 && a=1 && b<=9)
    {

    summ=a*b;
    cout«"Введите ответ! : "«endl;
    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 << " Multiply by " << SecondChar << "?" <> Answer;
    if (Answer == FirstChar * SecondChar){
    cout << "Верно! This number: " << Answer;
    } else {
    cout << "Неверно! Correct answer: " << FirstChar * SecondChar << endl;
    }
    return 0;
    }

    1. Don't post your attempts at experimenting with code here.. Nobody needs this! (and no one will watch it).

      Comments are not for!

      1. If you can't cope, ask questions in the comments.. Isn’t that what he writes under the assignment??

      2. That's how it's written “who can't cope“, but not “who copes“? - feel the difference.
        And it is written “ask questions in the comments“, but it’s not written “post your code in the comments“.

        And, finally, editor site distorts C++ code, so it’s simply pointless to write it here, and no one will watch it.

  3. I don't understand the solution to the first problem. I solved it, but the code turned out to be simply huge, twice as much as this. why in your code, when entering 4 significant numbers, at the first correct one (true) answer, the operation does not end and it does not simply issue “Две тысячи”, 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. You can't delete comments?I'm talking about the code!If someone uses uncensored language, it will be somehow deleted?

      2. He probably doesn’t need it. But it would be great,if the comments only contained useful information,there is a lot in them,what complements the site!

  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. This is how I solved the third problem:

    1. Oops, something didn't come out right here, so I'll write it in the usual way:
      #include
      using namespace std;

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

      int num1 = 0;
      int num2 = 0;
      int answer = 0;

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

      cout <> otvet;

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

      return 0;
      }

      1. Read the comments carefully!Are you really not catching up???Write some more code:everyone will be interested,How did you write such a complex problem in an unusual and simple way?…

  7. f(x)=((sqrt(1.7*x+sin(x)^1/3 if 0<x<=2;
    cos(pi*x)+tgx if 2<x<=6 how to solve a problem using C++, Help

Leave a Reply

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