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. 1#include
    2using namespace std;
    3int main (){
    4 setlocale (0,””);
    5 int variable1 = 0;
    6 variable_2 int = 0;
    7 int variable 3 = 0;
    8 cout<<"Введіть два цілих однозначних числа і результат їх множення:"<<endl;
    9 cout<<"Введіть число 1"<>variable1;
    11 cout<<"Введіть число 2"<>variable2;
    13 cout<<"Введіть результат множення чисел 1 та 2"<>variable3;
    15 if((variable1=10))
    16 cout<<"Ви неправильно ввели чсло 1"<<endl;
    17 if((variable2=10))
    18 cout<<"Ви неправильно ввели чсло 2"<<endl;
    19 if (variable1*variable2==variable3)
    20 cout<<"Гаро множиш"<<endl;
    21 if (variable1 * variable_2!=variable3)
    22 cout<<"Помилка"<<endl;
    23 return 0;
    24}
    line does not work 15 and 17 if I enter numbers, for example 0 and 10, and in response, writing 0, vybyvaet term 20. What is this code wrong ?

    1. Обрати внимание if (variable1==10) – so it will be correctly, = Is the assignment symbol… You ask a condition that if the variable is 10, the same in the second if..

      1. to enter the number you need to write is not cout (this conclusion), What а>>

      2. You can always write in this order here:

        if( 10 == vfriable1 ) ...

        Then you'll never be wrong.
        Useful habit.

  2. #include “stdafx.h”
    #include

    using namespace std;

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

    int a, b;
    int f;

    cout <> a;
    cout <> b;

    cout << endl;

    cout <> f;

    if (f == a * b)
    {
    cout << "Ответ " << f << " is " << a << "*" << b << endl;
    }
    else
    {
    cout << "Ответ " << f << " not equal to " << a << "*" << b << endl;
    }

    cout << endl;
    system("pause");

    return 0;
    }

  3. somehow it was not displayed quite correctly, some pieces were cut out

    #include
    using namespace std;
    int main()
    { setlocale(LC_ALL, “rus”);
    cout << "проверка знаний на таблицу умножений" << endl;
    int i, a, b, x; //create variables for work
    cout << "введите первое число от 1 to 10 " <> a; //assign the entered result to a variable
    cout << "введите второе число от 1 to 10 " <> b; //assign the entered result to variable b
    x = a*b; // We multiply the entered data and write it to the variable x
    cout << "Введите как вам кажется результат умножения " << a << " x " << b <> i; //we ask the user to enter the result and write it to the variable i
    if (ix){ cout << "учите таблицу умножения, correct answer: " << x << endl; }//compare the results
    else{ cout << "ВЕРНО!!! Вы знаете таблицу умножения "; }
    system("pause");
    return 0;}

  4. #include
    #include
    #include
    using namespace std;
    int main(void)
    {
    setlocale(0, “”);
    int a, b;
    int c = 0;
    cout <> a;
    cout <> b;
    cout <> c;
    {
    if (c == a*b)
    cout << "Ваш ответ сходится с результатом калькулятора!" << endl;
    else
    cout << "Это неправильный ответ. Correct answer = " << a * b << endl;
    }
    system("pause");
    return 0;
    }

  5. Honestly, I didn't understand the first problem…. For those who don't mind, please explain…

    1. what is not clear? A task – enter a four-digit amount – the program displays it in words and with the correct ending of the name of the currency at the end – 1234 – one thousand two hundred thirty-four dollars

  6. Wrote code for the first problem with an ATM.
    The code turned out not so beautiful, as in the answer, but I wrote it myself, no prompts)
    It seems to work, but was grateful, if “tested”..

      1. Why do so many people ignore it?:that they ask not to write the code here?))maybe they want,to be praised?

      2. Don't want to – don't read. And don't be responsible for everyone. Ok?
        I, for example, I'm looking at that, what others write.

Leave a Reply

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