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. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int num_1, num_2, result, answer;
    cout << "Введите два однозначных числа: " <> num_1;
    cin >> num_2;
    cin >> answer;
    result = num_1 * num_2;

    if (num_1 > 9 && num_2 > 9 && num_1 < 0 && num_2 < 0) {
    cout << "Вы ввели не однозначное число " << endl;
    }
    else if (result == answer) {
    cout << "Вы ввели правильный ответ! " << result;
    }
    else if (answer != result) {
    cout << "Вы ввели не правильный ответ!\n Correct answer: " << result << endl;
    }

    }

    1. #include
      using namespace std;
      int main()
      {
      cout << "пожалуйста , введите два однозначных числа " <> num1 >> num2;
      cout << "напишите ответ умножения данных чисел " <> total;
      int total1 = num1 * num2;
      if (total = total1) {
      cout << "yes , baby" << endl;

      }
      else {
      cout << "no, baby" << endl;
      cout << total1 << endl;
      }
      return 0;

      }

  2. if(num1 > 9 && num2 > 9 || num1 < 0 && num2 < 0)
    {
    cout << "Вы ввели неоднозначное число " << endl;
    This line of code goes unnoticed ! Everything else worked out. Tell me ,what did you do wrong ?

  3. #include
    using namespace std;

    void main()
    {
    setlocale(LC_ALL, “rus”);
    int a, b, result, answer;
    cout << "тест на знание таблицы умножения, enter 2 number" <> a >> b;
    cout << "теперь введите произведение этих двух чисел" <> answer;
    result = a * b;

    if (result == answer)
    {
    cout << "Правильно, do you know the multiplication table" << endl;
    }

    else if (answer != result)
    {
    cout << "не правильно, correct answer: " << result << endl;
    }
    }

  4. #include

    using namespace std;

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

    int x,Y,from;
    x=0;
    y=0;
    z=0;
    cout<<"Введите 2 числа"<>x>>Y;

    switch(from) {
    case’*’:
    cout<<x*y;
    break;
    }

    cout<>from;
    if (z==x*y){
    cout<<"\n"<<"Верно";

    }
    else
    if(from!= X * y){

    cout<<"\n"<<"Неверно"<<"\n"<<"x*y="<<x*y;

    }
    return 0;
    }

  5. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    system(“color A “);
    char again;
    do
    {
    int First;
    int Second;
    cout << "Введите первое число " <> First;
    cout << "Введите второе число " <> Second;
    cout << "Умножь " << First << " on " << Second <> through;
    if(thrid == First * Second)
    {
    cout << "Молодец! you multiplied correctly!\n Do you want to show who is the god of the multiplication table?\n";

    }
    else
    {
    cout << "Чеел, you made a mistake, попробуй еще раз\n Докажи что ты бог таблицы умножения\n";
    }
    cout <> again;
    } while (again == ‘Y’);
    }

  6. int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    cout << "Введите 2 integers…" << endl;;
    cout <> a;
    cout <> b;
    c = a * b;
    cout << "Сейчас я вам задам простую математическую задачу второго класса…" << endl;

    cout << "Я ваc попрошу умножить первое число на второе, and enter your answer in the box below." << endl;

    cout <> d;

    if (c == d)
    {
    cout << "Да, все верно";
    }
    if (c != d)
    {
    cout << "Нет, this is not true, answer " << c<< " will be true" << endl;
    }

  7. #include
    using namespace std;

    int main()
    {
    setlocale(0, “.1251”);
    int n1, n2, on one, result;
    cout <> n1;
    cout <> n2;
    cout <> on one;
    result = n1 * n2;
    if (num == result) {
    cout << "Правильно!";
    }
    else {
    cout << "Не правильно (" << endl;
    cout << "Правильный ответ: " << result << endl;
    }
    return 0;
    }

  8. #include

    using namespace std;

    int main() {
    setlocale(LC_ALL, “RU”);
    int x, Y;
    double a, b;

    cout << "Введите 1-е число " <> x;
    cout << "Введите 2-е число " <> Y;

    cout << "Введите произведение чисел " <> a;

    b = x * Y;
    if (a != b)
    cout << "Неправильно, correct answer " << b << endl;
    else cout << "Молодец! Правильно ";

    return 0;
    }

Leave a Reply

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