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.

254 thoughts on “Tasks: Select if and else statements in c ++

  1. LIKE SO…
    #include “pch.h”
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL,”RUS”);
    int a, b, c, d;
    cout << "Введите 2 number" <> a >> b;
    cout << "Введите результат сложения двух чисел" <> d;
    c = a * b;

    if (d == c)
    {
    cout << "Отв Верн" << endl;
    }

    else if(d!=c)
    {
    cout << "Вы ввели не правильный ответ" << endl;
    cout << "Правильный ответ=" << c << endl;
    }
    }

  2. #include
    using namespace std;

    int main() {
    setlocale(LC_ALL, “russian”);
    int first = 0;
    int second = 0;
    int third= 0;
    int d = 0;
    cout <> first;
    cout <> second;
    cout <> d;
    third = first * second;
    if (d == third) {
    cout << "Ответ верный" << endl;

    }
    else if (d != third) {
    cout << "Ответ не правильный" << endl;
    cout << "Правильный ответ=" << third << endl;
    }
    system("pause");
    return 0;

  3. #include

    using namespace std;

    void main() {

    setlocale(LC_ALL, “ru”);

    int a = 0, b = 0, otvet = 0;

    cout << "Введите два числа\n" <> a;
    cout <> b;
    cout <> otvet;

    if (a * b == otvet)
    {
    cout << "\nВы ответили правильно. Composition " << a << " and " << b << " will be equal to " << a * b;
    }
    else if (a * b != otvet) {
    cout << "\nК сожалению, you answered incorrectly. Result product " << a << " and " << b << " is equal to " << a * b;
    }
    cout << "\n\n\n\n\n\n";
    }

  4. About scoring four-digit number:
    int main()
    {
    setlocale(LC_ALL, “rus”);
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    start :
    int ch,your,today,of the,ed;
    cout < 9999: “;
    cin >> ch;
    if (ch > 9999)
    {
    cout << "Сказал же, не больше! ";
    goto start;
    }
    if (ch ==0)
    {
    cout << "Бомжара))\n";
    goto start;
    }
    if (ch <0)
    {
    cout << "Долги? I sympathize)\n";
    goto start;
    }

    else
    {
    = ch / 1000;
    switch (your)
    {
    case 1:
    cout << "Одна тысяча ";
    break;
    case 2:
    cout << "Две тысячи ";
    break;
    case 3:
    cout << "Три тысячи ";
    break;
    case 4:
    cout << "Четыре тысячи ";
    break;
    case 5:
    cout << "Пять тысяч ";
    break;
    case 6:
    cout << "Шесть тысяч ";
    break;
    case 7:
    cout << "Семь тысяч ";
    break;
    case 8:
    cout << "Восемь тысяч ";
    break;
    case 9:
    cout << "Девять тысяч ";
    break;
    case 0:
    cout << "";
    break;
    }
    said ch = % 1000;
    today / = 100;
    switch (today)
    {
    case 1:
    cout << "сто ";
    break;
    case 2:
    cout << "двести ";
    break;
    case 3:
    cout << "триста ";
    break;
    case 4:
    cout << "четыреста ";
    break;
    case 5:
    cout << "пятьсот ";
    break;
    case 6:
    cout << "шестьсот ";
    break;
    case 7:
    cout << "семьсот ";
    break;
    case 8:
    cout << "восемьсот ";
    break;
    case 9:
    cout << "девятьсот ";
    break;
    case 0:
    cout << "";
    break;
    }

    of = ch % 1000;
    of = the % 100;
    of = the / 10;

    switch (of the)
    {
    case 1:
    {
    of = ch % 1000;
    of = the % 100;
    if (of == 10)
    cout << "десять";
    if (of == 11)
    cout << "одинадцать долларов";
    if (of == 12)
    cout << "двенадцать долларов";
    if (of == 13)
    cout << "тринадцать долларов";
    if (of == 14)
    cout << "четырнадцать долларов";
    if (of == 15)
    cout << "пятнадцать долларов";
    if (of == 16)
    cout << "шестнадцать долларов";
    if (of == 17)
    cout << "семнадцать долларов";
    if (of == 18)
    cout << "восемнадцать долларов";
    if (of == 19)
    cout << "девятнадцать долларов";

    goto end;
    break;
    }
    case 2:
    cout << "двадцать ";
    break;
    case 3:
    cout << "тридцать ";
    break;
    case 4:
    cout << "сорок ";
    break;
    case 5:
    cout << "пятьдесят ";
    break;
    case 6:
    cout << "шестьдесят ";
    break;
    case 7:
    cout << "семьдесят ";
    break;
    case 8:
    cout << "восемьдесят ";
    break;
    case 9:
    cout << "девяносто ";
    break;
    case 0:
    cout << "";
    break;
    }
    ed = ch % 1000 % 100 % 10;
    switch (ed)
    {
    case 1:
    cout << "один доллар";
    break;
    case 2:
    cout << "два доллара";
    break;
    case 3:
    cout << "три доллара";
    break;
    case 4:
    cout << "четыре доллара";
    break;
    case 5:
    cout << "пять долларов";
    break;
    case 6:
    cout << "шесть долларов";
    break;
    case 7:
    cout << "семь долларов";
    break;
    case 8:
    cout << "восемь долларов";
    break;
    case 9:
    cout << "девять долларов";
    break;
    case 0:
    cout << "";
    break;
    }
    end:
    if (ch % 10 == 0) cout << " долларов";

    cout << ".\n";
    goto start;
    }
    }

      1. What is it about ostache of the division you are interested in ? As it applies to this task , or?

    1. And if you are in this program, for example 12 shalt bring, you will not give an answer “twelve dollars two dollars”?

      1. No, will not give. On the number of 11 to 19 established a separate code

    2. creepy govnokod. Even with such vypendrezhem some kindergarten.
      That's how it's done.
      #include

      using namespace std;

      int main()
      {
      setlocale(LC_ALL, “rus”);
      start:
      int sum = 0;
      cout << "Введите желаемую сумму снятия(to 9999): " <> sum;
      if (sum > 9999 || sum < 1)
      {
      cout << "Введена некорректная сумма. Try again" <= 20)
      {
      a = sum % 10;
      }

      if (sum == 1)
      {
      cout << "Вы снимаете: " << sum << " US" << endl;
      }
      if (sum == 2 || sum == 3 || sum == 4)
      {
      cout << "Вы снимаете: " << sum << " dollar" << endl;
      }
      if (a == 0 || sum == 5 || sum == 6 || sum == 7 || sum == 8 || sum == 9 || sum == 10 || sum == 11 || sum == 12 || sum == 13 || sum == 14 || sum == 15 || sum == 16 || sum == 17 || sum == 18 || sum == 19)
      {
      cout << "Вы снимаете: " << sum << " долларов" << endl;
      }
      if (a == 5 || a == 6 || a == 7 || a == 8 || a == 9)
      {
      cout << "Вы снимаете: " << sum << " долларов" << endl;
      }
      if (a == 1)
      {
      cout << "Вы снимаете: " << sum << " US" << endl;
      }
      if (a == 2 || a == 3 || a == 4)
      {
      cout << "Вы снимаете: " << sum << " dollar" << endl;
      }

      system("pause");
      return 0;

      }

      1. Show off just you , such that the formulation..
        He wrote as he could, works. I am just learning. Everything is working.
        I hope you picked up your CDA. Good luck

      2. Drugs.. you have a number of cursive writing, or int is int? GMS, as pontovatsya, and eventually crap…

  5. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL,”RUS”);
    int a,b,c,d;
    cin>>a>>b;

    cout<>c;

    d=a*b;

    if(c==d)
    {
    cout<<"Ответ: "<<c<<" верный";
    }

    else
    {
    cout<<"Ответ: "<<c<<" не верный ответ"<<", correct answer: "<<d;
    }
    }

  6. int num1, num2, otvet;

    cout << "Программа для проверки таблицы умножения:" << endl;

    cout << "Введите первое число:" <> num1;
    cout << "Введите первое число:" <> num2;

    cout << "Введите произведение этих чисел:" <> otvet;

    int variant1;
    num1 num2 = variant1 *;
    if (otvet == variant1){
    cout << "Вы ответили верно!!!!\n";
    }
    else if (otvet != variant1){
    cout << "Вы ответили не верно!!!!\n" <<
    "Правильный ответ : " << variant1 << endl;
    }

  7. #include
    using namespace std;

    int main()

    {
    setlocale(0, “”);
    int a, b, d;

    cout <> a;
    cout <> b;
    cout <> d;
    int c = a*b;
    if (d==c)
    {
    cout << "Овет верен." << endl;
    }
    else if (d != c) {
    cout << "Вы ввели неправильный ответ." << endl;
    cout << "Правильный ответ:" << c << endl;
    }
    system("pause");
    return 0;
    }

  8. #include
    #include
    #include
    #include

    using namespace std;

    int main() {
    int x;
    int y;
    int answer;
    int result;
    string iAm;
    cin >> x >> Y;
    result = x* y;
    if (x > 10 || Y > 10) {
    cout << "U sure u can do it ?-? (y / n)" <> iAm;
    if (iAm == “Y”) {
    cout <> answer;
    if (answer == result) {
    cout << "Just lucky, you'll not get it next time ^-^";
    cout << "This time the answer is " << result;
    }else{
    cout << "Dont worry, it was complicated (naah it wasn't)" << endl;
    cout << "The RIGHT answer is " << result;
    }
    }else{
    if (iAm == "n") {
    cout <> answer;
    if (answer == result) {
    cout << "Just lucky, you'll not get it next time ^-^" << endl;
    cout << "This time the answer is " << result;
    }else{
    cout << "Back to 1st grade boy, ur wrong!!" << endl;
    cout << "The RIGHT answer is " << result;
    }
    }
    return 0;
    }

    1. it somehow formatted my code, so some shit is off, sorry
      just made my code wrong….
      what a clever website

Leave a Reply

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