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 “stdafx.h”
    #include

    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int a, b;
    int a = 0;
    cout << "Введите два числа которые мы будем умножать=" <> a >> b;
    do {
    cout << "сколько будет " << a << " * " << b <> O;
    if (the a * b ==) {
    cout << a << " * " << b << " = " << O << endl;
    cout << "молодчина!" << endl;
    }
    else if (a * b != o) {
    cout << "Тебе стоит подучить таблицу умножения…" << endl;
    }
    } while (a * b != o);

    return 0; // if you are interested… while a cycle. i.e.. still has not answered correctly dick release. D

  2. The first task is really interesting, but I can not say that a simple. Even after the discovery of the code had to spend time to understand. Now, difficulties with the addition of other types of currencies. I would be grateful for the help.

  3. task №3
    program “TEST” assessment of knowledge multiplication table. “TEST” consists of 5 Examples yakyi user enters their own. Each answer gives pravelna 1 ball. Self awareness.
    #include
    #include

    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “Ukrainian”);
    system(“color A”);

    int a;
    int b;
    resulting int;
    int user_rezult;
    int i = 0;

    for (int j = 0; j < 5; j )
    {
    for (;;)
    {
    cout <> a;
    cout <> b;
    if (a >= 0 && a = 0 && b <= 9)
    {
    break;
    }
    }

    cout <> user_rezult;

    if (user_rezult != (a * b))
    {
    cout << " Try again " << endl;
    cout << a << " * " << b << " = " << user_rezult << endl;
    }
    else
    {
    cout << " Good job " << endl;
    cout << a << " * " << b << " = " << user_rezult << endl;
    ++i;
    }
    }

    cout << "Your point = " << i << endl;

    _getch();
    return 0;
    }

  4. #include
    using namespace std;

    int main() {

    int x, a, b, c, d, from;

    cout<>x;

    a = x000/1000;
    b = x00/100;
    c = x0/10;
    d = x;
    z = x% 100;

    if(a==1) cout<<"One thousand ";
    else if(a==2) cout<<"Two thousand ";
    else if(a==3) cout<<"Three thousand ";
    else if(a==4) cout<<"Four thousand ";
    else if(a==5) cout<<"Five thousand ";
    else if(a==6) cout<<"Six thousand ";
    else if(a==7) cout<<"Seven thousand ";
    else if(a==8) cout<<"Eight thousand ";
    else if(a==9) cout<<"Nine thousand ";

    if(b==1) cout<<"one hundred ";
    else if(b==2) cout<<"two hundred ";
    else if(b==3) cout<<"three hundred ";
    else if(b==4) cout<<"four hundred ";
    else if(b==5) cout<<"five hundred ";
    else if(b==6) cout<<"six hundred ";
    else if(b==7) cout<<"seven hundred ";
    else if(b==8) cout<<"eight hundred ";
    else if(b==9) cout<<"nine hundred ";

    else if(with 11 ==) cout<<"eleven dollars";
    else if(with 12 ==) cout<<"twelve dollars";
    else if(with 13 ==) cout<<"thirteen dollars";
    else if(with 14 ==) cout<<"fourteen dollars";
    else if(with 15 ==) cout<<"fifteen dollars";
    else if(with 16 ==) cout<<"sixteen dollars";
    else if(with 17 ==) cout<<"seventeen dollars";
    else if(with 18 ==) cout<<"eighteen dollars";
    else if(with 19 ==) cout<<"nineteen dollars";

    else if(c==2) cout<<"twenty ";
    else if(c==3) cout<<"thirty ";
    else if(c==4) cout<<"fourty ";
    else if(c==5) cout<<"fifty ";
    else if(c==6) cout<<"sixty ";
    else if(c==7) cout<<"seventy ";
    else if(c==8) cout<<"eighty ";
    else if(c==9) cout<<"ninety ";

    else if(d==1) cout<<"one dollars";
    else if(d==2) cout<<"two dollars";
    else if(d==3) cout<<"three dollars";
    else if(d==4) cout<<"four dollars";
    else if(d==5) cout<<"five dollars";
    else if(d==6) cout<<"six dollars";
    else if(d==7) cout<<"seven dollars";
    else if(d==8) cout<<"eight dollars";
    else if(d==9) cout<<"nine dollars";

    if(x00==000) cout<<"dollars";
    else if(x0==00) cout<<"dollars";
    else if(x0==10) cout<<"ten dollars";
    else if(x==0) cout<<"dollars";

    cout<<endl<<endl;

    return 0;
    }

  5. In the first task:

    #include “stdafx.h”
    #include
    #include

    using namespace std;

    string thousend(int x);
    string sto(int x, bool t);
    string desyat(int x, bool t, bool s);
    string edin(int x, bool t, bool s, bool d);

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

    int number;

    cout <> number) || (number > 9999) || (number < 0 )) //input validation
    {
    cin.clear();
    while (cin.get() != '\n')
    continue;
    cout < 999) // thousands
    {
    flag_is_1000 = true;
    cout << thousend(number / 1000) << " ";
    number %= 1000;
    }

    bool flag_is_100 = false; //greater number flag 100
    if ((number 99)) //hundreds of
    {
    flag_is_100 = true;
    cout << table(number / 100, flag_is_1000) << " ";
    number %= 100;
    }

    bool flag_is_10 = false; //greater number flag 20
    if ((number 19)) //dozens of
    {
    flag_is_10 = true;
    cout << desyat(number / 10, flag_is_1000, flag_is_100) << " ";
    number %= 10;
    }

    cout << Follow(number, flag_is_1000, flag_is_100, flag_is_10) << endl;

    return 0;
    }

    string thousend(int x)
    {
    string thousend;
    if (x == 1) thousend = "Одна тысяча";
    if (x == 2) thousend = "Две тысячи";
    if (x == 3) thousend = "Три тысячи";
    if (x == 4) thousend = "Четыре тысячи";
    if (x == 5) thousend = "Пять тысяч";
    if (x == 6) thousend = "Шесть тысяч";
    if (x == 7) thousend = "Семь тысяч";
    if (x == 8) thousend = "Восемь тысяч";
    if (x == 9) thousend = "Девять тысяч";
    return thousend;
    }
    string sto(int x, bool t)
    {
    string styo;
    if (x == 1) styo = "Сто";
    if (x == 2) styo = "Двести";
    if (x == 3) styo = "Триста";
    if (x == 4) styo = "Четыреста";
    if (x == 5) styo = "Пятьсот";
    if (x == 6) styo = "Шестьсот";
    if (x == 7) styo = "Семьсот";
    if (x == 8) styo = "Восемьсот";
    if (x == 9) styo = "Девятьсот";
    if (t == true) styo[0] = tolower(styo[0]); //if more than one thousand, the hundreds of small letters
    return styo;
    }
    string desyat(int x, bool t, bool s)
    {
    string des;
    if (x == 2) des = "Двадцать";
    if (x == 3) des = "Трицать";
    if (x == 4) des = "Сорок";
    if (x == 5) des = "Пятьдесят";
    if (x == 6) des = "Шестьдесят";
    if (x == 7) des = "Семьдесят";
    if (x == 8) des = "Восемьдесят";
    if (x == 9) des = "Девяносто";
    if (t == true || s == true) of the[0] = tolower(of the[0]); //if more than a hundred, the dozens of small letters
    return des;
    }
    string edin(int x, bool t, bool s, bool d)
    {
    string ed;
    if (x == 0) ed = "рублей.";
    if (x == 1) ed = "Один рубль.";
    if (x == 2) ed = "Два рубля.";
    if (x == 3) ed = "Три рубля.";
    if (x == 4) ed = "Четыре рубля.";
    if (x == 5) ed = "Пять рублей.";
    if (x == 6) ed = "Шесть рублей.";
    if (x == 7) ed = "Семь рублей.";
    if (x == 8) ed = "Восемь рублей.";
    if (x == 9) ed = "Девять рублей.";
    if (x == 10) ed = "Десять рублей.";
    if (x == 11) ed = "Одиннадцать рублей.";
    if (x == 12) ed = "Двенадцать рублей.";
    if (x == 13) ed = "Тринадцать рублей.";
    if (x == 14) ed = "Четырнадцать рублей.";
    if (x == 15) ed = "Пятнадцать рублей.";
    if (x == 16) ed = "Шестнадцать рублей.";
    if (x == 17) ed = "Семнадцать рублей.";
    if (x == 18) ed = "Восемнадцать рублей.";
    if (x == 19) ed = "Девятнадцать рублей.";
    if (t == true || s == true || d == true) ed[0] = tolower(ed[0]); //If more than ten, the unit with a small letter
    return ed;

    }

  6. 3-I task
    #include “stdafx.h”
    #include
    using namespace std;

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

    cout << "введите первое число для умножения" <> a;
    cout << "введите второе число для умножения" <> b;
    cout << " how many will be if " << a << " multiplied by " << b << endl << " enter the result " <> sum;
    if (sum != a*b) { cout << "вы ошиблись " << endl << "правильный ответ= " << a * b << endl; }
    if (sum==a*b) { cout << " you have entered the correct result " << endl; }

    return 0;
    }

  7. The third task

    #include “stdafx.h”
    #include
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “Russian”);
    unsigned short int a, b, c;
    cout << "Введите два однозначных числа: " <> a;
    cin >> b;
    cout << "Перемножьте эти числа и впишите результат: " <> c;
    if (c == a*b) {
    cout << "Вы умножили правильно!";
    }
    else {
    cout << "Неверно, correct answer: " << a * b;
    }

    _getch();
    return 0;
    }

Leave a Reply

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