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
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “Rus”);
    cout << "\t Программа для проверки пользователи\n\tна знание таблицы умножения";
    double a, b,c ;
    cout << "\nВведите два числа для умножения\n";
    cout <> a;
    cout <> b;
    cout << "\n Выполните умножение " << a << " on " << b << ", and enter your answer." << endl;
    cout <> c;
    if (a * b == c)
    cout << "Вы посчитали правильно, keep it up!";
    else
    {
    cout << "Вы посчитали не правильно, be careful next time!\n"; cout << "Правильный ответ = " << a * b;
    }
    cout << "\n\n";
    return 0;

    1. #include
      using namespace std;

      int main() {
      setlocale(LC_ALL, “ru”);
      int a, b, c , d;

      cout<> a;
      cout <> b;
      cout <> c;
      d = a * b;

      if (cd) {
      cout << "Ответ не верный! :(\n";
      cout << "Правильный ответ: " << d;
      }
      else
      cout << "Ответ верный! :)";

      return 0;
      }

  2. #include
    using namespace std;

    int main()
    {
    int firstNumber, secondNubmer, trueNumber, answerByUser;
    //adding Russian language support
    setlocale(LC_ALL, “rus”);

    cout << "Введите два числа однозначных числа" <> firstNumber;
    cout << "Введите второе число" <> secondNubmer;

    //checking if the entered number is correct
    if (firstNumber && secondNubmer > 10) {
    cout << "Вы ввели число привышающее 10!";
    }
    else {
    //request a response from the user
    cout << firstNumber << " * " << secondNubmer << " = your answer?" <> answerByUser;

    //logically correct answer
    trueNumber = firstNumber * secondNubmer;

    //comparing the user's answer with a logically correct answer
    if (answerByUser == trueNumber) {
    cout << "Верно";
    }
    else {
    cout << "Ответ не верный";
    }
    }
    }

  3. Dollar program(nothing is difficult, logical operators are everything)
    #include

    using namespace std;

    int main()
    {
    int money;
    cout <> money;
    int last = money;
    if(last == 1){
    cout << money << " Dollar" << endl;
    }
    else if(last == 2 || last == 3 || last == 4){
    cout << money << " Dollar" << endl;
    }
    else{
    cout << money << " Dollars" << endl;
    }

    }

    1. #include
      using namespace std;

      int main()
      {
      setlocale(LC_ALL, “RUS”);
      int firstNumber, secondNumber, result, resultTrue;

      cout << "Введите два целых, single digit numbers" <> firstNumber >> secondNumber;
      if (!(firstNumber < 10) || !(secondNumber < 10))
      {
      cout << "Вы ввели не однозначное число!!!";
      }
      else
      {
      cout << "Результат умножения: " << firstNumber << " NA " << secondNumber <> result;
      resultTrue = firstNumber * secondNumber;

      if (result == resultTrue)
      {
      cout << "Вы ответили правильно" << endl;
      cout << firstNumber << " * " << secondNumber << " = " << result;
      }
      else
      {
      cout << "Вы ответили неправильно" << endl << "Правильный ответ: " << endl;
      cout << firstNumber << " * " << secondNumber << " = " << resultTrue;
      }

      }

    2. The problem statement stated, so that the entire amount is withdrawn in words, and not just change the ending in a word.
      #include
      using namespace std;

      int main()
      {
      setlocale(0, “”);
      int a = 0;
      cout <> a;
      cout << "С вашего счета снято ";
      int b = 0;
      int c = 0;
      int d = 0;
      int i = 0;
      if (a < 20) {
      a = b;
      if (b == 19) {
      cout << " nineteen rubles " << endl;
      }
      else if (b == 18) {
      cout << " eighteen rubles " << endl;
      }
      else if (b == 17) {
      cout << " seventeen rubles " << endl;
      }
      else if (b == 16) {
      cout << " sixteen rubles " << endl;
      }
      else if (b == 15) {
      cout << " fifteen rubles " << endl;
      }
      else if (b == 14) {
      cout << " fourteen rubles " << endl;
      }
      else if (b == 13) {
      cout << " thirteen rubles " << endl;
      }
      else if (b == 12) {
      cout << " twelve rubles " << endl;
      }
      else if (b == 11) {
      cout << " eleven rubles " << endl;
      }
      else if (b == 10) {
      cout << " ten rubles " << endl;
      }
      else if (b == 9) {
      cout << " nine rubles " << endl;
      }
      else if (b == 8) {
      cout << " eight rubles " << endl;
      }
      else if (b == 7) {
      cout << " seven rubles " << endl;
      }
      else if (b == 6) {
      cout << " six rubles " << endl;
      }
      else if (b == 5) {
      cout << " five rubles " << endl;
      }
      else if (b == 4) {
      cout << " four rubles " << endl;
      }
      else if (b == 3) {
      cout << " three rubles " << endl;
      }
      else if (b == 2) {
      cout << " two rubles " << endl;
      }
      else if (b == 1) {
      cout << " one ruble " < 19) && (a < 100)) {
      c = a / 10;
      b = a % 10;
      if (c == 2) {
      cout << c << b << "двадцать";
      } if (c == 3) {
      cout << c << b << "тридцать";
      } if (c == 4) {
      cout << c << b << "сорок";
      } if (c == 5) {
      cout << c << b << "пятьдесят";
      } if (c == 6) {
      cout << c << b << "шестьдесят";
      } if (c == 7) {
      cout << c << b << "семьдесят";
      } if (c == 8) {
      cout << c << b << "восемьдесят";
      } if (c == 9) {
      cout << c << b << "девяносто";
      }
      else if (b == 9) {
      cout << " nine rubles " << endl;
      }
      else if (b == 8) {
      cout << " eight rubles " << endl;
      }
      else if (b == 7) {
      cout << " seven rubles " << endl;
      }
      else if (b == 6) {
      cout << " six rubles " << endl;
      }
      else if (b == 5) {
      cout << " five rubles " << endl;
      }
      else if (b == 4) {
      cout << " four rubles " << endl;
      }
      else if (b == 3) {
      cout << " three rubles " << endl;
      }
      else if (b == 2) {
      cout << " two rubles " << endl;
      }
      else if (b == 1) {
      cout << " one ruble " << endl;
      }
      else if (b == 0) {
      cout << " rubles " < 99) && (a < 1000)) {
      d = a / 100;
      c = a % 100;
      b = c % 10;
      c = c / 10;
      if (d == 1) {
      cout << d << c << b << " сто ";
      } if (d == 2) {
      cout << d << c << b << " двести ";
      } if (d == 3) {
      cout << d << c << b << " тристо ";
      } if (d == 4) {
      cout << d << c << b << " четыресто ";
      } if (d == 5) {
      cout << d << c << b << " пятьсот ";
      } if (d == 6) {
      cout << d << c << b << " шестьсот ";
      } if (d == 7) {
      cout << d << c << b << " семьсот ";
      } if (d == 8) {
      cout << d << c << b << " восемьсот ";
      } if (d == 9) {
      cout << d << c << b << " девятьсот ";
      } if (c == 0) {
      cout << "";
      } if (c == 2) {
      cout << "двадцать";
      } if (c == 3) {
      cout << "тридцать";
      } if (c == 4) {
      cout << "сорок";
      } if (c == 5) {
      cout << "пятьдесят";
      } if (c == 6) {
      cout << "шестьдесят";
      } if (c == 7) {
      cout << "семьдесят";
      } if (c == 8) {
      cout << "восемьдесят";
      } if (c == 9) {
      cout << "девяносто";
      } if (c == 1) {
      b = b + 10;
      if (b == 19) {
      cout << " nineteen rubles " << endl;
      }
      else if (b == 18) {
      cout << " eighteen rubles " << endl;
      }
      else if (b == 17) {
      cout << " seventeen rubles " << endl;
      }
      else if (b == 16) {
      cout << " sixteen rubles " << endl;
      }
      else if (b == 15) {
      cout << " fifteen rubles " << endl;
      }
      else if (b == 14) {
      cout << " fourteen rubles " << endl;
      }
      else if (b == 13) {
      cout << " thirteen rubles " << endl;
      }
      else if (b == 12) {
      cout << " twelve rubles " << endl;
      }
      else if (b == 11) {
      cout << " eleven rubles " << endl;
      }
      else if (b == 10) {
      cout << " ten rubles " << endl;
      }
      }
      else if (b == 9) {
      cout << " nine rubles " << endl;
      }
      else if (b == 8) {
      cout << " eight rubles " << endl;
      }
      else if (b == 7) {
      cout << " seven rubles " << endl;
      }
      else if (b == 6) {
      cout << " six rubles " << endl;
      }
      else if (b == 5) {
      cout << " five rubles " << endl;
      }
      else if (b == 4) {
      cout << " four rubles " << endl;
      }
      else if (b == 3) {
      cout << " three rubles " << endl;
      }
      else if (b == 2) {
      cout << " two rubles " << endl;
      }
      else if (b == 1) {
      cout << " one ruble " << endl;
      }
      else if (b == 0) {
      cout << " rubles " < 999) && (a < 10000)) {
      i = a / 1000;
      d = a % 1000;
      c = d % 100;
      b = c % 10;
      d = d / 100;
      c = c / 10;
      if (i == 1) {
      cout << i << d << c << b << " одна тысяча ";
      } if (i == 2) {
      cout << i << d << c << b << " две тысячы ";
      } if (i == 3) {
      cout << i << d << c << b << " три тысячы ";
      } if (i == 4) {
      cout << i << d << c << b << " четыре тысячы ";
      } if (i == 5) {
      cout << i << d << c << b << " пять тысяч ";
      } if (i == 6) {
      cout << i << d << c << b << " шесть тысяч ";
      } if (i == 7) {
      cout << i << d << c << b << " семь тысяч ";
      } if (i == 8) {
      cout << i << d << c << b << " восемь тысяч ";
      } if (i == 9) {
      cout << i << d << c << b << " девять тысяч ";
      } if (d == 0) {
      cout << "";
      } if (d == 1) {
      cout << "сто ";
      } if (d == 2) {
      cout << "двести ";
      } if (d == 3) {
      cout << "тристо ";
      } if (d == 4) {
      cout << "четыресто ";
      } if (d == 5) {
      cout << "пятьсот ";
      } if (d == 6) {
      cout << "шестьсот ";
      } if (d == 7) {
      cout << "семьсот ";
      } if (d == 8) {
      cout << "восемьсот ";
      } if (d == 9) {
      cout << "девятьсот ";
      } if (c == 0) {
      cout << "";
      } if (c == 2) {
      cout << "двадцать";
      } if (c == 3) {
      cout << "тридцать";
      } if (c == 4) {
      cout << "сорок";
      } if (c == 5) {
      cout << "пятьдесят";
      } if (c == 6) {
      cout << "шестьдесят";
      } if (c == 7) {
      cout << "семьдесят";
      } if (c == 8) {
      cout << "восемьдесят";
      } if (c == 9) {
      cout << "девяносто";
      } if (c == 1) {
      b = b + 10;
      if (b == 19) {
      cout << " nineteen rubles " << endl;
      }
      else if (b == 18) {
      cout << " eighteen rubles " << endl;
      }
      else if (b == 17) {
      cout << " seventeen rubles " << endl;
      }
      else if (b == 16) {
      cout << " sixteen rubles " << endl;
      }
      else if (b == 15) {
      cout << " fifteen rubles " << endl;
      }
      else if (b == 14) {
      cout << " fourteen rubles " << endl;
      }
      else if (b == 13) {
      cout << " thirteen rubles " << endl;
      }
      else if (b == 12) {
      cout << " twelve rubles " << endl;
      }
      else if (b == 11) {
      cout << " eleven rubles " << endl;
      }
      else if (b == 10) {
      cout << " ten rubles " << endl;
      }
      }
      else if (b == 9) {
      cout << " nine rubles " << endl;
      }
      else if (b == 8) {
      cout << " eight rubles " << endl;
      }
      else if (b == 7) {
      cout << " seven rubles " << endl;
      }
      else if (b == 6) {
      cout << " six rubles " << endl;
      }
      else if (b == 5) {
      cout << " five rubles " << endl;
      }
      else if (b == 4) {
      cout << " four rubles " << endl;
      }
      else if (b == 3) {
      cout << " three rubles " << endl;
      }
      else if (b == 2) {
      cout << " two rubles " << endl;
      }
      else if (b == 1) {
      cout << " one ruble " << endl;
      }
      else if (b == 0) {
      cout << " rubles " << endl;
      }
      }
      else {
      cout << "Извините произошла ошибка при вводе ";
      }
      system("pause");
      return 0;
      }

  4. int result, num1, num2;
    Console.WriteLine(“Enter the first number for the arithmetic operation:”);
    num1 = int.Parse(Console.ReadLine());
    Console.WriteLine(“Enter the second number for the arithmetic operation:”);
    num2 = int.Parse(Console.ReadLine());

    Console.WriteLine($”Result of multiplying a number {num1} on {num2} “);
    Console.WriteLine(new string(‘-‘,40));

    Console.WriteLine();

    Console.Write($”Enter the correct answer: {num1} * {num2} enter answer = “);

    result = int.Parse(Console.ReadLine());

    if (num1 * num2 == result)
    {
    Console.WriteLine(“You did it”);
    }
    else
    {
    Console.WriteLine(“You counted incorrectly!The correct result is {0} “, num1 * num2);
    }

  5. Hello, I can’t see the answer to problems on the topic “Select if and else statements in c ++”
    not clickable “see code”
    Thank you.

  6. #include
    #include

    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a, thousand1, sot1, des1,ed1;
    string tis,today,of the,ed;
    cin >> a;
    if (a/1000==1)
    {
    tis = “thousand “;
    tis1 = 1000;
    }
    else if(a/1000==2)
    {
    tis = “two thousand “;
    tis1 = 2000;
    }
    else if (a/1000==3)
    {
    tis = “three thousand “;
    tis1 = 3000;
    }
    else if(a/1000==4)
    {
    tis= “four thousand “;
    tis1 = 4000;
    }
    else if (a/1000==5)
    {
    tis = “five thousand “;
    tis1 = 5000;
    }
    else if(a/1000==6)
    {
    tis = “six thousand “;
    tis1 = 6000;
    }
    else if (a/1000==7)
    {
    tis = “seven thousand “;
    tis1 = 7000;
    }
    else if (a/1000==8)
    {
    tis = “8 thousand “;
    tis1 = 8000;
    }
    else if (a/1000==9)
    {
    tis = “nine thousand “;
    tis1 = 9000;
    }
    else
    {
    tis=””;
    tis1 = 0;
    }

    if ((a-tis1)/100==1)
    {
    sot = “сто”;
    sot1 = 100;
    }
    else if ((a-tis1)/100==2)
    {
    sot = “двести”;
    sot1 = 200;
    }
    else if ((a-tis1)/100==3)
    {
    sot = “триста”;
    sot1 = 300;
    }
    else if ((a-tis1)/100==4)
    {
    sot = “четыреста”;
    sot1 = 400;
    }
    else if ((a-tis1)/100==5)
    {
    sot = “пятьсот”;
    sot1 = 500;
    }
    else if ((a-tis1)/100==6)
    {
    sot = “шестьсот”;
    sot1 = 600;
    }
    else if ((a-tis1)/100==7)
    {
    sot = “семьсот”;
    sot1 = 700;
    }
    else if ((a-tis1)/100==8)
    {
    sot = “восемьсот”;
    sot1 = 800;
    }
    else if ((a-tis1)/100==9)
    {
    sot = “девятьсот”;
    sot1 = 900;
    }
    else
    {
    sot=””;
    sot1=0;
    }

    if ((a-tis1-sot1)/10==2)
    {
    of = “двадцать”;
    des1 = 20;
    }
    else if ((a-tis1-sot1)/10==3)
    {
    of = “тридцать”;
    des1 = 30;
    }
    else if ((a-tis1-sot1)/10==4)
    {
    of = “сорок”;
    des1 = 40;
    }
    else if ((a-tis1-sot1)/10==5)
    {
    of = “пятьдесят”;
    des1 = 50;
    }
    else if ((a-tis1-sot1)/10==6)
    {
    of = “шестьдесят”;
    des1 = 60;
    }
    else if ((a-tis1-sot1)/10==7)
    {
    of = “семьдесят”;
    des1 = 70;
    }
    else if ((a-tis1-sot1)/10==8)
    {
    of = “восемьдесят”;
    des1 = 80;

    }
    else if ((a-tis1-sot1)/10==9)
    {
    of = “ninety”;
    des1 = 90;
    }
    else if ((a-tis1-sot1)/10==0)
    {
    of =””;
    des1 = 0;
    }

    else if ((a-tis1-sot1)/10==1)
    {

    of = “”;
    des1 = 10;
    if ((a-tis1-sot1-des1)%10==1)
    {
    ed = “одинадцать долларов”;
    ed1 = 1;
    cout << tis << today<< of the<<ed;
    return 0;
    }
    else if ((a-tis1-sot1-des1)%10==2)
    {
    ed = "двенадцать долларов";
    ed1 = 2;
    cout << tis << today<< of the<<ed;
    return 0;
    }
    if ((a-tis1-sot1-des1)%10==3)
    {
    ed = "тринадцать долларов";
    ed1 = 3;
    cout << tis << today<< of the<<ed;
    return 0;
    }
    if ((a-tis1-sot1-des1)%10==4)
    {
    ed = "четырнадцать долларов";
    ed1 = 4;
    cout << tis << today<< of the<<ed;
    return 0;
    }
    if ((a-tis1-sot1-des1)%10==5)
    {
    ed = "пятнадцать долларов";
    ed1 = 5;
    cout << tis << today<< of the<<ed;
    return 0;
    }
    if ((a-tis1-sot1-des1)%10==6)
    {
    ed = "шестнадцать долларов";
    ed1 = 6;
    cout << tis << today<< of the<<ed;
    return 0;

    }
    if ((a-tis1-sot1-des1)%10==7)
    {
    ed = "семнадцать долларов";
    ed1 = 7;
    cout << tis << today<< of the<<ed;
    return 0;
    }
    if ((a-tis1-sot1-des1)%10==8)
    {
    ed = "восемнадцать долларов";
    ed1 = 8;
    cout << tis << today<< of the<<ed;
    return 0;
    }
    if ((a-tis1-sot1-des1)%10==9)
    {
    ed = "девятнадцать долларов";
    ed1 = 9;
    cout << tis << today<< of the<<ed;
    return 0;
    }
    }
    if (a==1)
    {
    ed = "один доллар";

    }
    else if (a==2)
    {
    ed = "два доллара";

    }
    else if (a==3)
    {
    ed = "три доллара";

    }
    else if (a==4)
    {
    ed = "четыре доллара";

    }
    else if (a==5)
    {
    ed = "пять долларов";

    }
    else if (a==6)
    {
    ed = "шесть долларов";

    }
    else if (a==7)
    {
    ed = "семь долларов";

    }
    else if (a==8)
    {
    ed = "восемь долларов";

    }
    else if (a==9)
    {
    ed = "девять долларов";

    }
    else
    {
    ed =" долларов";

    }

    cout << tis << today<< of the<<ed;
    }

  7. int main() {
    setlocale(LC_ALL, “rus”);
    int summa = 0;
    int a, b, c, d, e;
    cout <> sum;
    cout << endl;
    if (summa = 10000) {
    cout <> sum;
    cout << endl;
    }
    cout << "Сумма к выдачи:" << endl;
    cout < 8999) && (a < 10000))
    cout < 7999) && (a < 9000))
    cout < 6999) && (a < 8000))
    cout < 5999) && (a < 7000))
    cout < 4999) && (a < 6000))
    cout < 3999) && (a < 5000))
    cout < 2999) && (a < 4000))
    cout < 1999) && (a < 3000))
    cout < 999) && (a < 2000))
    cout << "Одна тысяча ";
    else
    cout < 899) && (b < 1000))
    cout < 799) && (b < 900))
    cout < 699) && (b < 800))
    cout < 599) && (b < 700))
    cout < 499) && (b < 600))
    cout < 399) && (b < 500))
    cout < 299) && (b < 400))
    cout < 199) && (b < 300))
    cout < 99) && (b < 200))
    cout << "Сто ";
    else
    cout < 89) && (c < 100))
    cout < 79) && (c < 90))
    cout < 69) && (c < 80))
    cout < 59) && (c < 70))
    cout < 49) && (c < 60))
    cout < 39) && (c < 50))
    cout < 29) && (c < 40))
    cout < 19) && (c < 30))
    cout << "Двадцать ";
    else if (c == 19)
    cout << "Девятьнадцать ";
    else if (c == 18)
    cout << "Восемьнадцать ";
    else if (c == 17)
    cout << "Семьнадцать ";
    else if (c == 16)
    cout << "Шестьнадцать ";
    else if (c == 15)
    cout << "Пятьнадцать ";
    else if (c == 14)
    cout << "Четырнадцать ";
    else if (c == 13)
    cout << "Тринадцать ";
    else if (c == 12)
    cout << "Двенадцать ";
    else if (c == 11)
    cout << "Одинадцать ";
    else if (c == 10)
    cout << "Десять ";
    else
    cout < 9) && (c < 20))
    cout << "";
    else if (d == 9)
    cout << "Девять ";
    else if (d == 8)
    cout << "Восемь ";
    else if (d == 7)
    cout << "Семь ";
    else if (d == 6)
    cout << "Шесть ";
    else if (d == 5)
    cout << "Пять ";
    else if (d == 4)
    cout << "Четыре ";
    else if (d == 3)
    cout << "Три ";
    else if (d == 2)
    cout << "Два ";
    else if (d == 1)
    cout << "Один ";
    else
    cout < 9) && (c < 20))
    cout << "долларов";
    else if (e == 1)
    cout < 1) && (e < 5))
    cout << "доллара";
    else
    cout << "долларов";
    cout << " =-";
    return 0;
    }

Leave a Reply

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