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, “ru”);
    int number_1, number_2, answer;
    number_1 = 0;
    number_2 = 0;
    cout <> number_1 >> number_2;
    cout <> answer;
    if (answer == number_1 * number_2)
    {
    cout << "You answer true" << endl;
    }
    else
    {
    cout << "You answer false" <<"!\n" << "" << "True answer :" << number_1 * number_2 << endl;
    }
    return 0;

    }

  2. #include
    using namespace std;
    void main()
    {
    int num1, num2;
    int Answer;
    cout << "Multiplication checking." << endl;
    cout << "Enter the first number:" <> num1;
    cout << "Enter the second number:" <> num2;
    cout << "Enter answer:" <> Answer;
    if (Answer==num1*num2)
    {
    cout << "You right" << endl;
    }
    else
    {
    cout << " Answer is wrong. Right is:" << num1 * num2 << endl;

  3. #include
    using namespace std;

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

    int num1, num2, answer, answertrue;

    num1 = 0;
    num2 = 0;
    answer = 0;
    answertrue = 0;

    cout <> num1;
    cout <> num2;
    cout <> answer;

    answertrue = num1 * num2;

    if (num1 * num2 == answer)
    cout << "\nПравильно!";

    else if (num1 * num2 != answer)
    cout << "\nНе верно! correct answer: " << num1 << " * " << num2 << " = " << answertrue << endl;

    return 0;

    }

    В итоге получилось так, максимально проще как по мне, хотя мб есть что сократить

    1. #include
      using namespace std;

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

      int num1, num2, answer, answertrue;

      num1 = 0;
      num2 = 0;
      answer = 0;
      answertrue = 0;

      cout <> num1;
      cout <> num2;
      cout <> answer;

      answertrue = num1 * num2;

      if (num1 * num2 == answer)
      cout << "\nПравильно!";

      else if (num1 * num2 != answer)
      cout << "\nНе верно! correct answer: " << num1 << " * " << num2 << " = " << answertrue << endl;

      return 0;

      }

      Почему то не верно скопировалось

  4. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL,”Russian”);
    cout << "Введи два числа от 1 to 10 для их произведения: " <> a;
    cin >> b;
    if (a>10||a10||b<1)
    cout <> vers;
    if(c == vers)
    cout << "Верно";
    else
    cout << "Неверно, правильеный ответ " << c;

    }
    }

  5. // Áàòóò ðàáîòàåò!
    #include
    using namespace std;
    int main (){
    setlocale (0,”rus”);
    int hands =0;
    cout <> hands;
    if (hands == 1){
    cout << "Ââåä¸í íîìåð áîëüøîãî ïàëüöà " <<endl;
    }
    else if (hands == 2){
    cout << "Ââåä¸í íîìåð óêàçàòåëüíîãî ïàëüöà " <<endl;
    }
    else if (hands == 3){
    cout << "Ââåä¸í íîìåð ñðåäíåãî ïàëüöà " <<endl;
    }
    else if (hands == 4){
    cout << "Ââåä¸í áåç èìÿííûé íîìåð ïàëüöà " <<endl;
    }
    else if (hands == 5){
    cout << "Ââåä¸í íîìåð ìåçèíåö ïàëüöà " <<endl;
    }
    else {
    cout << "Ó âàñ íåò ïàëüöà ):" ;
    }

    }

  6. //Батут Работает!
    #include
    using namespace std;
    int main (){
    setlocale (0,”rus”);
    int hands =0;
    cout <> hands;
    if (hands == 1){
    cout << "Введён номер большого пальца " <<endl;
    }
    else if (hands == 2){
    cout << "Введён номер укакзательного пальца " <<endl;
    }
    else if (hands == 3){
    cout << "Введён номер среднего пальца " <<endl;
    }
    else if (hands == 4){
    cout << "Введён без имянный номер пальца " <<endl;
    }
    else if (hands == 5){
    cout << "Введён номер мезинец пальца " <<endl;
    }
    else {
    cout << "К сожалению У вас нет такого пальца):"
    }

    }

  7. #include

    int main()
    {
    setlocale(LC_ALL, “rus”);
    std::cout <> number_1;
    int number_2;
    std::cout <> number_2;

    std::cout << number_1 << " * " << number_2 << " = " << " ? " << std::endl;
    std::cout <> user_otvet;
    if (user_otvet == verniy_otvet)
    std::cout << "Ваш ответ верный" << std::endl;
    else
    std::cout << "Ваш ответ неверен. Правильным был " << verniy_otvet << std::endl;
    }

    У меня получилось так в 3-ем задании.

  8. #include

    int main ()
    {
    int number1 = 0;
    int number2 = 0;
    int result = 0;

    std::cout <> number1;

    std::cout <> number2;

    number1*=number2;

    std::cout <> result ;

    if (result == number1)
    std::cout << number1 << " i'ts correct" ;

    else
    std::cout << "correct answer is " << number1;
    return 0;

    }

Leave a Reply

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