#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
int enterNumber = 0;
cout << "Введите целое число (от 1 до 9999): ";
cin >> enterNumber;
// проверяем входит ли введенное число в заданный диапазон
if (enterNumber <= 0 ||enterNumber > 9999)
cout << "Число не входит в диапазон от 1 до 9999!\n";
else // если да - приступаем к выводу на экран
{
cout << "\nВы ввели: ";
// чтобы добраться до первой цифры в введенном числе
// (если оно четырехзначное), надо это число поделить
// на 1000 и взять от него остаток от деления на 10
// например 8 888 / 1000 = 8 (888 тысячные отбрасываются
// т.к. введенное число типа int), далее 8 % 10 = 8
// так же не ошибитесь с оператором == (равно)
if ((enterNumber / 1000) % 10 == 1) cout << "Одна тысяча ";
else if ((enterNumber / 1000) % 10 == 2) cout << "Две тысячи ";
else if ((enterNumber / 1000) % 10 == 3) cout << "Три тысячи ";
else if ((enterNumber / 1000) % 10 == 4) cout << "Четыре тысячи ";
else if ((enterNumber / 1000) % 10 == 5) cout << "Пять тысяч ";
else if ((enterNumber / 1000) % 10 == 6) cout << "Шесть тысяч ";
else if ((enterNumber / 1000) % 10 == 7) cout << "Семь тысяч ";
else if ((enterNumber / 1000) % 10 == 8) cout << "Восемь тысяч ";
else if ((enterNumber / 1000) % 10 == 9) cout << "Девять тысяч ";
if ((enterNumber / 100) % 10 == 1) cout << "сто ";
else if ((enterNumber / 100) % 10 == 2) cout << "двести ";
else if ((enterNumber / 100) % 10 == 3) cout << "триста ";
else if ((enterNumber / 100) % 10 == 4) cout << "четыреста ";
else if ((enterNumber / 100) % 10 == 5) cout << "пятьсот ";
else if ((enterNumber / 100) % 10 == 6) cout << "шестьсот ";
else if ((enterNumber / 100) % 10 == 7) cout << "семьсот ";
else if ((enterNumber / 100) % 10 == 8) cout << "восемьсот ";
else if ((enterNumber / 100) % 10 == 9) cout << "девятьсот ";
if ((enterNumber / 10) % 10 == 1)
{
if (enterNumber % 10 == 0) cout << "десять долларов";
else if (enterNumber % 10 == 1) cout << "одинадцать долларов";
else if (enterNumber % 10 == 2) cout << "двенадцать долларов";
else if (enterNumber % 10 == 3) cout << "тринадцать долларов";
else if (enterNumber % 10 == 4) cout << "четырнадцать долларов";
else if (enterNumber % 10 == 5) cout << "пятнадцать долларов";
else if (enterNumber % 10 == 6) cout << "шестнадцать долларов";
else if (enterNumber % 10 == 7) cout << "семнадцать долларов";
else if (enterNumber % 10 == 8) cout << "восемнадцать долларов";
else if (enterNumber % 10 == 9) cout << "девятнадцать долларов";
}
if ((enterNumber / 10) % 10 == 2) cout << "двадцать ";
else if ((enterNumber / 10) % 10 == 3) cout << "тридцать ";
else if ((enterNumber / 10) % 10 == 4) cout << "сорок ";
else if ((enterNumber / 10) % 10 == 5) cout << "пятьдесят ";
else if ((enterNumber / 10) % 10 == 6) cout << "шестьдесят ";
else if ((enterNumber / 10) % 10 == 7) cout << "семьдесят ";
else if ((enterNumber / 10) % 10 == 8) cout << "восемьдесят ";
else if ((enterNumber / 10) % 10 == 9) cout << "девяносто ";
if ((enterNumber / 10) % 10 != 1)
{
if (enterNumber % 10 == 0) cout << "долларов";
else if (enterNumber % 10 == 1) cout << "один доллар";
else if (enterNumber % 10 == 2) cout << "два доллара ";
else if (enterNumber % 10 == 3) cout << "три доллара ";
else if (enterNumber % 10 == 4) cout << "четыре доллара ";
else if (enterNumber % 10 == 5) cout << "пять долларов ";
else if (enterNumber % 10 == 6) cout << "шесть долларов ";
else if (enterNumber % 10 == 7) cout << "семь долларов ";
else if (enterNumber % 10 == 8) cout << "восемь долларов ";
else cout << "девять долларов ";
}
}
cout << endl << endl;
return 0;
}
I did this the second time, but the first one didn’t work out…
#includeusing namespace std;
void main()
{
int i =0;
cout <> i;
switch (i)
{
case 1:
cout << "thumb\n";
break;
case 2:
cout << "forefinger\n";
break;
case 3:
cout << "long finger\n";
break;
case 4:
cout << "ring finger\n";
break;
case 5:
cout << "little finger\n";
break;
default:
cout << "Error\n";
break;
}
}
Last task
#includeusing namespace std;
void main()
{
setlocale(LC_ALL, "Rus");
int i = 0, j = 0, rezult = 0, sum = 0;
cout <> i >> j;
sum = i * j;
cout <> rezult;
if (sum == rezult)
cout << "Поздравляем ответ правильный!\n";
else
cout << "\nУчите таблицу умножения!!!\n";
}
My version of isolating numbers from numbers, entered by the user in the first task. No division, no leftovers.
int summ;cout <> summ;
int num[6]{0, 0, 0, 0, 0, 0};
int minus[6]{100000, 10000, 1000, 100, 10, 1};
summ++;
for (int i = 0; i 0)
{
summ = summ - minus[i];
num[i]++;
}
if (num[i] > 0)
{
num[i]--;
summ = summ + minus[i];
}
}
I also scored phrases through arrays:
string hungreds[9]{"Сто ", "Двести ", "Триста ", "Четыреста ", "Пятьсот ", "Шестьсот ", "Семьсот ", "Восемьсот ", "Девятьсот "};string second_ten[9]{"одиннадцать ", "двенадцать ", "тринадцать ", "четырнадцать ", "пятнадцать ", "шестнадцать ", "семнадцать ", "восемнадцать ", "девятнадцать "};
string tens[9]{"десять ", "двадцать ", "тридцать ", "сорок ", "пятьдесят ", "шестьдесят ", "семьдесят ", "восемьдесят ", "девяносто "};
string nums[9]{"одна ", "две ", "три ", "четыре ", "пять ", "шесть ", "семь ", "восемь ", "девять "};
string numss[9]{"один ", "два ", "три ", "четыре ", "пять ", "шесть ", "семь ", "восемь ", "девять "};
if (num[0] != 0 || num[1] != 0 || num[2] != 0)
{
if (num[0] != 0)
cout << hungreds[num[0] - 1];
if (num[1] == 1 && num[2] != 0)
cout << second_ten[num[2] - 1];
else
{
if (num[1] != 0)
cout << tens[num[1] - 1];
if (num[2] != 0)
cout << nums[num[2] - 1];
}
if (num[2] == 1 && num[1] != 1)
cout << "тысяча ";
else if ((num[2] == 2 || num[2] == 3 || num[2] == 4) && num[1] != 1)
cout << "тысячи ";
else cout << "тысяч ";
}
if (num[3] != 0)
cout << hungreds[num[3] - 1];
if (num[4] == 1 && num[5] != 0)
cout << second_ten[num[5] - 1];
else
{
if (num[4] != 0)
cout << tens[num[4] - 1];
if (num[5] != 0)
cout << numss[num[5] - 1];
}
if (num[5] == 1 && num[4] != 1)
cout << "рубль." << endl;
else if ((num[5] == 2 || num[5] == 3 || num[5] == 4) && num[4] != 1)
cout << "рубля." << endl;
else cout << "рублей." << endl;
#include#include
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
int object = 0 ;
int o1000 = 0 ;
int o100 = 0 ;
int o10 = 0 ;
int o1 = 0 ;
int isc = 0; //исключения(одиннадцать, пятнадцать и т.д.)
cout <> object;
o1000 = object / 1000;
o100 = (object / 100) % 10;
o10 = (object / 10) % 10;
o1 = object % 10;
isc = object % 100;
if (o1000 == 1)
cout << " Тысяча ";
if (o1000 == 2)
cout << " Две тысячи";
if (o1000 == 3)
cout << " Три тысячи ";
if (o1000 == 4)
cout << " Четыре тысячи ";
if (o1000 == 5)
cout << " Пять тысяч ";
if (o1000 == 6)
cout << " Шесть тысяч ";
if (o1000 == 7)
cout << " Семь тысяч ";
if (o1000 == 8)
cout << " Восемь тысяч ";
if (o1000 == 9)
cout << " Девять тысяч ";
if (o100 == 1)
cout << " сто ";
if (o100 == 2)
cout << " двести ";
if (o100 == 3)
cout << " триста ";
if (o100 == 4)
cout << " четыриста ";
if (o100 == 5)
cout << " пятьсот ";
if (o100 == 6)
cout << " шестьсот ";
if (o100 == 7)
cout << " семьсот ";
if (o100 == 8)
cout << " восемьсот ";
if (o100 == 9)
cout << " девятьсот ";
if (isc == 11)
cout << " одиннадцать рублей. \n";
if (isc == 12)
cout << " двенадцать рублей. \n";
if (isc == 13)
cout << " тринадцать рублей. \n";
if (isc == 14)
cout << " четырнадцать рублей. \n ";
if (isc == 15)
cout << " пятнадцать рублей. \n";
if (isc == 16)
cout << " шестнадцать рублей. \n";
if (isc == 17)
cout << " семнадцать рублей. \n";
if (isc == 18)
cout << " восемнадцать рублей. \n";
if (isc == 19)
cout << " девятнадцать рублей. \n";
if (o10 == 1)
cout << " десять рублей. \n ";
if (o10 == 2)
cout << " двадцать ";
if (o10 == 3)
cout << " тридцать ";
if (o10 == 4)
cout << " сорок ";
if (o10 == 5)
cout << " пятьдесят ";
if (o10 == 6)
cout << " шестьдесят ";
if (o10 == 7)
cout << " семьдесят ";
if (o10 == 8)
cout << " восемьдесят ";
if (o10 == 9)
cout << " девяносто ";
if ((o1 == 1) && (o10 != 1))
cout << " один рубль \n ";
if ((o1 == 2) && (o10 != 1))
cout << " два рубля. \n ";
if ((o1 == 3) && (o10 != 1))
cout << " три рубля. \n ";
if ((o1 == 4) && (o10 != 1))
cout << " четыре рубля. \n ";
if ((o1 == 5) && (o10 != 1))
cout << " пять рублей. \n ";
if ((o1 == 6) && (o10 != 1))
cout << " шесть рублей. \n ";
if ((o1 == 7) && (o10 != 1))
cout << " семь рублей. \n ";
if ((o1 == 8) && (o10 != 1))
cout << " восемь рублей. \n";
if ((o1 == 9) && (o10 != 1))
cout << " девять рублей. \n ";
if ((o1 == 0) && (o10 != 1))
cout << " рублей. \n ";
_getch();
return 0;
}
like this somehow
task №3.
True, it was not possible to set conditions on variables a and b.
#includeusing namespace std;
int main()
{
setlocale(0, "");
int a, b, p, np = 0;
cout << "\t\t\tПроверка таблицы умножения\nВы должны задать 2 числа и написать сумму произведения этих чисел\n\n\n";
cout << a;
cout << b;
cout << "Введите ответ на уравнение: " << a << " * " << b << np;
cout << endl;
p = a * b;
if ((a,b) <=9)
{
if (p != np) cout << "НЕ ПРАВИЛЬНО!\nСоветую выучить таблицу умножения!!!\n\n";
else if (p == np) cout << "ПРАВИЛЬНО!\n\n";
}
else cout << "Неверное число!";
return 0;
}
Good day! Here is my solution to task No. 1. True, not everything is done through the if statement. If there are any shortcomings or suggestions, unsubscribe, you are welcome.
#include
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int full_num , first_num , second_num , third_num , fourth_num , currency_num, cntrl = 0;
cout << "Введите ваше число: " <> full_num;
cout << "Выберите валюту для вывода: " << endl;
cout << "1. Dollars" << endl;
cout << "2. Euro" << endl;
cout << "3. Hryvnia" <> currency_num;
cout << endl;
fourth_num = full_num % 10;
full_num /= 10;
third_num = full_num % 10;
full_num /= 10;
second_num = full_num % 10;
full_num /= 10;
first_num = full_num;
switch (first_num)
{
case 0: {cout << "\0";break;}
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;}
}
switch (second_num)
{
case 0 : {cout << "\0"; break;}
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;}
}
switch (third_num)
{
case 0 : {cout << "\0"; break;}
case 1 : {if (fourth_num == 0) cout << "десять "; else cout << "\0"; 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 < 1) && fourth_num != 0)
{
switch (fourth_num)
{
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;}
}
}
else if (third_num == 1 && fourth_num != 0)
{
switch (fourth_num)
{
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;}
}
}
if (currency_num == 1)
{
if (fourth_num == 1 && third_num != 1) cout << "доллар" << endl;
else if (((fourth_num == 2 || fourth_num == 4) || fourth_num == 3) && third_num != 1) cout << "доллара" << endl;
else cout << "долларов" << endl;
}
else if (currency_num == 2) cout << "евро" << endl;
else
{
if (fourth_num == 1 && third_num != 1) cout << "гривна" << endl;
else if ((((fourth_num == 2 || fourth_num == 4) || fourth_num == 3) && third_num != 1) && cntrl != 1) cout << "гривны" << endl;
else cout << "гривен" << endl;
}
return 0;
}
I recommend displaying all switches() into the function Make the suffix as parameters of the function, serial number and prefix, which will be assigned to the root of the word as necessary, depending on the bit depth of the number. Then you get one switch() instead of 4
The recommendations function is clear. But the point is, that I was trying to write a program using only selection statements. And if you do it completely “Beautiful”, then you can use functions and loops. Then the code will be reduced significantly.
I don't think anyone will answer me, but I'll ask a question anyway :)
Why doesn't the solution to problem 3 work? ? I've already checked everything several times.:
#include
using namespace std;
int main() {
setlocale(LC_ALL, “rus”);
int a = 0, b = 0, c = 0, d = 0;
cout <> a;
cin >> b;
c = a * b;
cout <> d;
if (c = d) {
cout << "Ответ верный\n";
}
else
cout << "Ответ не верный. The correct answer is: \n" << c;
system("PAUSE");
return 0;
}
Something like this.
There are a lot of mistakes )))
#includeusing namespace std;
int main() {
setlocale(LC_ALL, "rus");
int a = 0, b = 0, c = 0, d = 0;
cout < < a; // почему cout а не cin ? cin >> b;
c = a * b;
cout < < d; // почему cout а не cin ? if (c = d) { // почему = а не == ? (тут ты присвоил переменной с значение d) cout << "Ответ верный\n"; } else cout << "Ответ не верный. Правильным ответом является: \n" << c; system("PAUSE"); return 0; }