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

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

    int a=0, b=0, result=0, out=0;

    cout << "Привет друг,let's test your knowledge of the multiplication table.nWrite the first number:" <> a;
    if (a <= 9 )
    {
    cout << "Введите второе число: " <> b;
    if (b <= 9)
    {
    cout << "Введите произведение чисел: " <> result;
    out = a * b;
    if (result == a * b)
    {
    cout << "Вы ввели правильный ответ! " << result;
    }
    else
    {
    cout << "Вы ввели не правильный ответ!\nCorrect answer: " << out << endl;
    }

    }

    else
    {
    cout << "Число должно быть не больше 9" << endl;
    }
    }
    else
    {
    cout << "Число должно быть не больше 9" << endl;
    }
    return 0;

    }

  2. #include
    #include
    #include
    #include
    using namespace std;
    int main(){
    int num,num2, number3;
    cout << "Введите два числа" <> on one >> num2;
    cout << "Введите правильный ответ: " <> number3;
    if (num*num2 == num3){
    cout << "Ответ верный" << endl;
    }else {
    cout << "Неправильный ответ" << endl;
    cout << "Правильный ответ: " << num*num2 << endl;

    }

    return(0);

    }

  3. int x,Y, from;
    cout << "введите первое число: " <> x;
    cout << "введите второе число: " <> Y;
    cout << "и чему же это равно?" <> from;

    if (x * Y != z)
    {
    cout << "неверно\nверный ответ: " << (x * Y) <<endl;
    }

    else
    {
    cout << "верно" << endl;
    }

  4. #include

    using namespace std;

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

    cout << "\t\tПРОВЕРКА ЗНАНИЙ ТАБЛИЦЫ УМОЖЕНИЯ" <<endl;
    cout <> a >> b;

    if ((a=0)&&(b=0))
    {
    cout << "Введите резултат умножения: " << a << "*" << b <> product;
    if( product != (a * b) )
    cout << "ОШИБКА!\t Correct answer: " << a * b << endl;
    else cout << "Поздровляем! Your answer is correct. " << endl;
    }
    else cout << "ЧИСЛА ДОЛЖНЫ БЫТЬ ОТ 0 UNTIL 10" << endl;

    }

  5. #include
    using namespace std;

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

    int a = 0;
    int b = 0;
    int c = 0;

    cout <> a;

    if (a 0)
    {
    cout <> b;

    if (b 0)
    {
    cout << "Запишите ответ умножения: " << a << "*" << b <> c;
    if (a * b == c) cout << "Поздравляю, this is the correct answer. ";
    else if (a * b != c) cout << "Это не правильный ответ. Correct answer: " << a * b;
    }
    else
    {
    cout << "Вы ввели число не из диапозона от 1 to 9. Повторите попытку.";
    }
    }
    else
    {
    cout << "Вы ввели число не из диапозона от 1 to 9. Повторите попытку.";
    }
    return 0;
    }

    1. #include
      using namespace std;

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

      int a = 0;
      int b = 0;
      int c = 0;

      cout <> a;

      if (a 0)
      {
      cout <> b;

      if (b 0)
      {
      cout << "Запишите ответ умножения: " << a << "*" << b <> c;
      if (a * b == c) cout << "Поздравляю, this is the correct answer. ";
      else if (a * b != c) cout << "Это не правильный ответ. Correct answer: " << a * b;
      }
      else
      {
      cout << "Вы ввели число не из диапазона от 1 to 9. Повторите попытку.";
      }
      }
      else
      {
      cout << "Вы ввели число не из диапазона от 1 to 9. Повторите попытку.";
      }
      return 0;
      }

  6. #include
    using namespace std;
    void main()
    {
    setlocale (LC_ALL, “ru”);

    int onenumber;
    int twonumber;
    int number;

    cout << "Введите два однозначных числа" <> onenumber;
    cin >> twonumber;

    cout << "Веедите результат умножения числа " << onenumber << " on " << twonumber << "?" <> number;

    if (onenumber * twonumber == number)
    {
    cout << "Правильно!" << endl;
    }
    else
    {
    cout << "НЕПРАВИЛЬНО!" << " Correct answer: " << onenumber * twonumber << endl;
    }
    }

  7. int main()
    {
    setlocale(0, “”);
    int a=0;
    int b = 0;
    int res = 0;
    start:
    cout <> a;
    cout <> b;
    if (a > 9 || b > 9)
    {
    cout << "\tчисла должны быть однозначными!!!" << endl;

    system("pause");
    system("cls");
    goto start;
    }
    else
    {
    cout <> res;

    if (res != a * b)
    {
    cout << "\tваш результат неверен!!!" << endl;
    cout << "\tправильный ответ: " << a * b << endl;
    }
    else if (res == a * b)
    {
    cout << "\tвсе верно, well done!!!" << endl;
    }

    }

    return 0;

    }

  8. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “ru”);
    const int i = 0;
    int cont;
    do
    {
    int a, b, ans, TrueAns;
    cout << "Введите 2 числа по очереди: " <> a >> b;
    cout << "Сколько будет: " << a << " * " << b << "?" <> ans;
    TrueAns = a * b;

    if (TrueAns == ans)
    {
    cout << "Ответ верный!" << endl;
    }
    else
    {
    cout << "Неверно! Correct answer: " << TrueAns << endl;
    }
    cout << "Желаете продолжить? Введите любое число больше 0 to continue: " <> account;
    } while (account > 0);
    return 0;
    }

Leave a Reply

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