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.

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

  1. # include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “rus”);
    int num1, num2, otvet, otvet1 = 0;
    cout <> num1;
    cout <> num2;
    cout <> answer1;
    answer = num1 * num2;
    if (otvet == otvet1) {
    cout << "Да";
    }
    else {
    cout << "Нет";
    }
    return 0;
    }

  2. Give recommendations , maybe something could be done better

    #include
    using namespace std;

    int main()
    {
    int a;
    int b;
    int result;
    cout <> a;
    cout <> b;
    cout << a <<" * " << b <> the result;

    if (result == a * b) {
    cout << " You are so good Bro )";
    }
    else {
    cout << "Nice try bro(";
    }

    return 0;
    }

  3. import java.util.Scanner;

    public class TwentyNineJule {
    public static void main(String[] args) {
    Scanner scaner = new Scanner(System.in);
    System.out.println(“First number: “);
    int x = scaner.nextInt();
    System.out.println(“Second number: “);
    int y = scaner.nextInt();
    System.out.println(“Your answer: “);
    int z = scaner.nextInt();
    if(z == x*y){
    System.out.println(“Correct”);
    }else {
    System.out.println(“Error”);
    System.out.println(“Correct answer is: “+x*y);
    }

    }
    }

  4. #include
    using namespace std;

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

    int num1 = 0;
    int num2 = 0;
    int answer = 0;

    cout <> num1;
    cin >> num2;
    cout << "результат умножения первого числа на второе: ? " <> answer;

    if (num1 * num2 == answer)
    {
    cout << "вы ввели правильный ответ! " << num1 * num2 << endl;
    }
    else if (num1 * num2 !=answer)
    {
    cout << "вы ввели не правильный ответ. Correct answer: " << num1 * num2 << endl;
    }
    return 0;
    }

  5. I decided to improve the program a little, to make the program work, until the user answers correctly:
    #include
    using namespace std;
    int main() {
    setlocale(LC_ALL, “RU”);
    int a, b, pro, user;
    cout <> a;
    cout <> b;
    pro = a * b;
    cout << "Введденные вами числа " << a << " " << b<<endl;
    cout <> user;

    while (bool yep = true) {
    if (pro == user)
    {
    cout << "Правильно!";
    yep = false;
    break;
    }
    else {
    cout << "Неправильно попробуй еще раз( \n";
    cout <> user;
    }
    }
    return 0;
    }

    1. the ending was copied
      else {
      cout << "Неправильно попробуй еще раз( \n";
      cout <> user;
      }
      }
      return 0;
      }

  6. int a, b, sum,result;

    cout <> a >> b;

    cin >> result;

    sum = a * b;

    if (sum == result)
    cout << "All Right : – ) \n";
    else
    cout << "Try again yet : – ( ";

  7. #include
    using namespace std;

    int main()
    {
    int a, b, c;
    cout <> a;
    cout <> b;
    cout <> c;

    if (c == a * b)
    cout << "Correct answer, good job!" << endl;

    else {
    cout << "Incorrect answer." << endl;
    cout << "Correct answer is " << (a * b) << endl;
    }

    return 0;
    }

    1. #include
      using namespace std;

      int main()
      {
      int a, b, c;
      cout <> a;
      cout <> b;
      cout <> c;
      if (c == a * b)
      cout << "Correct answer, good job!" << endl;
      else {
      cout << "Incorrect answer." << endl;
      cout << "Correct answer is " << (a * b) << endl;
      }

      return 0;
      }

  8. Гайс не знаю насколько это правильный ответ, но у меня получилось только так:

    #include
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “RU”);
    srand(time(NULL));
    int a = rand() % 10, b = rand() % 10, c;
    c = a * b;
    cout << "\t\t\t\t\t\tШкольные знания\n";

    cout << "Решите варажение: " << a << " * " << b <> a;

    cout << "Правильный ответ = "<< c << endl;

    return 0;
    }

Leave a Reply

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