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
    #include

    using namespace std;

    int main() {

    setlocale(LC_ALL, “RUS”);
    int number1;
    int number2;
    int ansver;
    cout << " Введите первое число: " <> number1;

    cout << " Введите второе число: " <> number2;
    cout << " The result of multiplying the first number by the second ? " <> responsible;

    if (ansver == number1 * number2)

    cout << " The answer is correct: " << responsible << endl;

    else {
    cout << " The answer is wrong! " << endl;
    cout << " Correct answer: " << responsible << endl;
    }

    }

  2. include

    using namespace std;

    int main(int argc, char const *argv[]){

    int num1;
    int num2;
    int otvet;

    cout << "Введите числа для умножения:" <> num1 >> num2;

    cout << "Введите ваш ответ:" <> otvet;

    if(otvet == (num1 * num2)){
    cout << "Правильно!!!" << endl << "Поздравляем!!!" << endl;
    }else{
    cout << "Не правильно(" << endl << num1 * num2 << " – вот правильный ответ." << endl;
    }

    return 0;
    }

  3. Классный задачник!!!
    Создателям большое спасибо)

  4. #include
    using namespace std;
    int main() {
    int a;int b; int c;
    cout<>a;
    cout<>b;
    cout<<a<<"*"<<b<>c;
    if(a*b==c) cout<<"Ответ верный"<<endl;
    else if(a * b!=c)cout<<"Не правильно\n"<<"ответ:"<<a * b<<endl;
    }

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

    int a, b, answer;
    cout<<"Введите первое число"<>a;
    cout<<"Введите второе число"<>b;
    cout<<"Результат умножения первого числа на второе?"<>answer;

    if(a*b==answer)
    {
    cout<<"Вы ответили правильно!"<<endl;
    }
    else
    {
    cout<<"Вы ответили неправильно!"<<endl;
    }

    }

  6. По левой руке только. Можно в начале предложить пользователю выбрать левую или правую руку, и уже от этого отталкиваться.
    Кст написал я на Russkoj move;

    #include
    using namespace std;

    int main()
    {
    int finger;
    while (true)
    {
    cout <> finger;
    switch (finger)
    {
    case 1:
    cout << "Mizinez" << endl;
    break;
    case 2:
    cout << "Bezimyannij" << endl;
    break;
    case 3:
    cout << "Srednij" << endl;
    break;
    case 4:
    cout << "Ukazatelnij" << endl;
    break;
    case 5:
    cout << "Bolshoj" << endl;
    break;
    default:
    cout << "Lol, mutant idiot" << endl;
    break;
    }
    }
    }

  7. #include
    using namespace std;

    int main(){
    cout << "Проверимся на таблицу умножения." << endl;
    int x = 0, y = 0, z = 0, d = 0;

    cout <> x;

    cout <> Y;

    z = x * Y;
    cout <> d;
    if(d != z){
    cout << "Ответ не правильный" << endl;
    cout << "Правльно будет " << from << endl;
    }
    else
    cout << "Верно…!" << endl;

    return 0;
    }

  8. 1I task
    ========================================
    #include
    #include
    using namespace std;

    void main()
    {
    setlocale(LC_ALL, “ru”);
    cout << "Введите сумму" <> sum;

    if (sum == 0)
    {
    cout << "ноль";
    return;
    }
    string result;
    int x1, x2, x3, x4;
    x1 = sum / 1000;
    x2 = sum / 100 % 10;
    x3 = sum / 10 % 10;
    x4 = sum % 10;
    switch (x1)
    {
    case 0:
    break;
    case 1:
    result += "тысяча ";
    break;
    case 2:
    result += "две тысячи ";
    break;
    case 3:
    result += "три тысячи ";
    break;
    case 4:
    result += "четыре тысячи ";
    break;
    case 5:
    result += "пять тысяч ";
    break;
    case 6:
    result += "шесть тысяч ";
    break;
    case 7:
    result += "семь тысяч ";
    break;
    case 8:
    result += "восемь тысяч ";
    break;
    case 9:
    result += "девять тысяч ";
    break;
    default:
    cout << "!ошибка ввода!\a";
    return;
    }
    switch (x2)
    {
    case 0:
    break;
    case 1:
    result += "сто ";
    break;
    case 2:
    result += "двести ";
    break;
    case 3:
    result += "триста ";
    break;
    case 4:
    result += "четыреста ";
    break;
    case 5:
    result += "пятьсот ";
    break;
    case 6:
    result += "шестсот ";
    break;
    case 7:
    result += "семьсот ";
    break;
    case 8:
    result += "восемьсот ";
    break;
    case 9:
    result += "девятьсот ";
    break;
    default:
    cout < 0) && (standing(last) < 20))
    {
    switch (standing(last))
    {
    case 1:
    result += "один доллар";
    break;
    case 2:
    result += "два доллара";
    break;
    case 3:
    result += "три доллара ";
    break;
    case 4:
    result += "четыре доллара";
    break;
    case 5:
    result += "пять долларов";
    break;
    case 6:
    result += "шесть долларов ";
    break;
    case 7:
    result += "семь долларов ";
    break;
    case 8:
    result += "восемь долларов ";
    break;
    case 9:
    result += "девять долларов ";
    break;
    case 10:
    result += "десять долларов ";
    break;
    case 11:
    result += "одиннадцать долларов ";
    break;
    case 12:
    result += "двенадцать долларов ";
    break;
    case 13:
    result += "тринадцать долларов ";
    break;
    case 14:
    result += "четырнадцать долларов ";
    break;
    case 15:
    result += "пятнадцать долларов ";
    break;
    case 16:
    result += "шестнадцать долларов ";
    break;
    case 17:
    result += "семнадцать долларов ";
    break;
    case 18:
    result += "восемнадцать долларов ";
    break;
    case 19:
    result += "девятнадцать долларов ";
    break;
    default:
    cout << "!ошибка ввода!\a";
    return;
    }
    }
    else
    {
    switch (x3)
    {
    case 0:
    break;
    case 2:
    result += "двадцать ";
    break;
    case 3:
    result += "тридцать ";
    break;
    case 4:
    result += "сорок ";
    break;
    case 5:
    result += "пятьдесят ";
    break;
    case 6:
    result += "шестьдесят ";
    break;
    case 7:
    result += "семьдесят ";
    break;
    case 8:
    result += "восемдесят ";
    break;
    case 9:
    result += "девяносто ";
    break;
    default:
    cout << "!ошибка ввода!\a";
    return;
    }
    switch (x4)
    {
    case 0:
    break;
    case 1:
    result += "один доллар ";
    break;
    case 2:
    result += "два доллара ";
    break;
    case 3:
    result += "три доллара ";
    break;
    case 4:
    result += "четыре доллара ";
    break;
    case 5:
    result += "пять долларов ";
    break;
    case 6:
    result += "шесть долларов ";
    break;
    case 7:
    result += "семь долларов ";
    break;
    case 8:
    result += "восемь долларов ";
    break;
    case 9:
    result += "девять долларов ";
    break;
    default:
    cout << "!ошибка ввода!\a";
    return;
    }
    }
    cout << result;
    }

    1. на сайт почему-то криво копируется, но суть понять можно

Leave a Reply

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