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.

|

## 257 thoughts on “Tasks: Select if and else statements in c ++”

1. Samorojy says:

setlocale(LC_ALL, “rus”);
int a = 0;
int b = 0;
cout <> a >> b;
a = a * b;
cout <> b;
if (a = b)
cout << "Вы ответили правильно\n";
else
cout <<"\nПравильный ответ:"<< a<< endl;
return 0;

2. Trimiam Black says:

#include
int main() {
std::cout << "Input first number " <> firstNumber;

std::cout << "Input second number " <> secondNumber;

std::cout << "How much is " << firstNumber << "* " << secondNumber << "? " <> multi;

if (multi == (firstNumber * secondNumber)) {
std::cout << "Your answer is correct! CONGRATULATIONS!!!" << std::endl;
}
else {
std::cout << "Your answer is not correct… :(( True answer is: " << (firstNumber * secondNumber) << std::endl;
};
return 0;
}

1. Trimiam Black says:

#include
int main() {
std::cout << "Input first number " <> firstNumber;

std::cout << "Input second number " <> secondNumber;

std::cout << "How much is " << firstNumber << "* " << secondNumber << "? " <> multi;

if (multi == (firstNumber * secondNumber)) {
std::cout << "Your answer is correct! CONGRATULATIONS!!!" << std::endl;
}
else {
std::cout << "Your answer is not correct… :(( True answer is: " << (firstNumber * secondNumber) << std::endl;
};
return 0;
}

1. Trimiam Black says:

Вообще не так вставлял

3. Wanserrf says:

#include
using namespace std;
int main()
{
setlocale(LC_ALL, “Russian”);
cout <> a;
cin >> b;
cout << a << "*" << b <> x;
if (c == x) {
cout << "Ваш ответ верный" << endl;
pass = false;
}
else { cout << "Ваш ответ неверен";
cout << "Попробуйте еще раз" << endl << a << "*" << b << "=";
}
}while (pass == true);

system("pause");
}

1. Wanserrf says:

Криво скопировал 6 строка cin >> a;

4. anonym says:

я тут еще немного усовершенствовал задачу

#include

using namespace std;

int main() {
setlocale(LC_ALL, “Rus”);
int a,b,c,e;
while (true) {
cout << "введите 2 number " <> a >> b;
c = a * b;
cout << "напишите свой ответ " <> e;
if(e==c){
cout << "молодец ты правельно решил " << endl;
}
else {
cout << "ты дурачек вот ответ: "<<c;
cout << endl;
}
}
system("pause");
return 0;
}

5. Denis says:

#include
using namespace std;
int main()
{ setlocale(LC_ALL, “ukr”);
int a,b,c;
cin>>a>>b;
cout<>c;
if(c!=a*b)
cout<<a * b;
else
cout<<"Правильно";
return 0;
}

6. citizen_10 says:

#include “pch.h”
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int a, b, multi;
cout << "Enter the two value for multiplying" <> a;
cin >> b;
cout <> multi;
if (multi == a * b)
cout << "Good job, indeed asnwer is:" << a * b << endl;
else
cout << "Bullshit. The asnwer is:" << a * b;
return 0;
}

7. Arthur says:

#include
using namespace std;

int main()
{
setlocale(0, “”);
double num;

cout <> on one;

if (num ==1) // Если введенное число меньше 10.
cout << "это первый палец." << endl;
if (num ==2) // Если введенное число меньше 10.
cout << "это второй палец." << endl;
if (num ==3) // Если введенное число меньше 10.
cout << "это третий палец." << endl;
if (num ==4) // Если введенное число меньше 10.
cout << "это четвертый палец." << endl;
if (num ==5) // Если введенное число меньше 10.
cout << "это пятый палец." << endl;

return 0;
}

8. n5kn5k says:

#include
using namespace std;

int main(){
int a,b,c,d;
A1:cout<<"enter 2 numbers"<<endl;
cout<>a;
cout<>b;
cout<<a<<"*"<<b<>d;
c=a*b;
if(d==c) cout<<"right\n";
if(d !=c) cout<<"wrong\n"<<"Right answer is:"<<a * b<<endl;
goto a1;
}

это рабочая программа 3 tasks