#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;
}
#include “stdafx.h”
#include
int main()
{
std::cout <> a >> b;
std::cout << "How much will " << a << "*" << b << "?" << std::endl;
std::cout <> c;
if (a * b == c) std::cout << "Well done, the answer is correct!\n";
else if (a * b != c) std::cout << "Sorry, the answer is not true! Go study! :(\n";
return 0;
}
Please help. I have a really hard time with tasks.
– – – – –
#include
using namespace std;
int main()
{
int a = 0;
int b = 0;
int c = a * b;
cout <> a;
cin >> b;
cout << "Результат умножения a * b ?";
if (c == a*b)
cout << "Правильно" << endl;
else if (c!== a * b)
cout << "Неправльно! Answer: " << c == a * b << endl << end;
system("pause");
return 0;
}
I'm not an expert, I just started learning C++ but try this.
You didn't name the directory at the beginning and else if the loop doesn't end
You also have an explanation in Russian, if you want it like that, add setlocale(LC_ALL, “rus”);
#include
using namespace std;
int main()
{
int a,b,c;
cout <> a;
cout <> b;
cout <> c;
if (c == a * b)
cout << "verno"<<endl;
else
cout << "ne verno "<<endl;
return 0;
}
#include
using namespace std;
int main()
{
int a,b,c;
cout <> a;
cout <> b;
cout <> c;
if (c == a * b)
cout << "verno"<<endl;
else
cout << "ne verno "<<endl;
return 0;
}
Why can’t I copy the script normally?. cin, \n swallowed? What crap.
I spent a long time reading through the comments on the 3rd problem and I don’t understand why people don’t have an entry point for data and the result of the product.
Here is my solution, please check and write a comment, Thank you.
int a = 0;
int b = 0;
int c = 0;
int d = 0;
cout <> a;
cout <> b;
cout <> d;
c = a * b;
if (d == c)
cout << "Otvet veren.";
if (d != c)
cout << "Otvet ne veren, " << "Pravil'nii otvet = " << c << endl;
and, understand, cin is erased in the comments >> .
I decided to share my last task.. Everything is working,but I can't get the program to work, when entering an ambiguous number, roll back to the very beginning. Therefore the program works for any number
#include
using namespace std;
int main (){
setlocale(LC_ALL,”rus”);
int FirstNumber = 0;
int SecondNumber = 0;
int answer;
cout<<"Программа для проверки знаний по таблице умножения."<<endl;
cout<<"=================================================="<<endl;
cout<<"Введите два однозначных числа"<<endl;
cout<>FirstNumber;
cout<>SecondNumber;
cout<<"Ответ:"<<FirstNumber<<"*"<<SecondNumber<>answer;
if (FirstNumber*SecondNumber==answer) cout<<"Ответ правильный!";
else if (FirstNumber*SecondNumberanswer) {cout<<"Ответ не правильный!"<<endl;
answer=FirstNumber*SecondNumber;
cout<<"Правильный ответ:"<<endl<<FirstNumber<<"*"<<SecondNumber<<"="<<answer;
}
return 0;
}
please comment on my logic in writing task No. 1.
The program performs the assigned task, but it differs radically from the author’s example. so I'm worried, maybe I'm thinking in the wrong direction, It's better to fix it at the beginning of training.
Thank you.
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int a(0);
cout <> a;
cout <= 1 && a <= 9999)
{
if ((a / 1000) % 10)
{
if ((a / 1000) % 10 == 1) cout << "одна тысяча ";
else if ((a / 1000) % 10 == 2) cout << "две тысячи ";
else if ((a / 1000) % 10 == 3) cout << "три тысячи ";
else if ((a / 1000) % 10 == 4) cout << "четыре тысячи ";
else if ((a / 1000) % 10 == 5) cout << "пять тысяч ";
else if ((a / 1000) % 10 == 6) cout << "шесть тысяч ";
else if ((a / 1000) % 10 == 7) cout << "семь тысяч ";
else if ((a / 1000) % 10 == 8) cout << "восемь тысяч ";
else cout << "девять тысяч ";
a %= 1000;
}
if ((a / 100) % 10)
{
if ((a / 100) % 10 == 1) cout << "сто ";
else if ((a / 100) % 10 == 2) cout << "двести ";
else if ((a / 100) % 10 == 3) cout << "триста ";
else if ((a / 100) % 10 == 4) cout << "четыреста ";
else if ((a / 100) % 10 == 5) cout << "пятьсот ";
else if ((a / 100) % 10 == 6) cout << "шестьсот ";
else if ((a / 100) % 10 == 7) cout << "семьсот ";
else if ((a / 100) % 10 == 8) cout << "восемьсот ";
else cout << "девятьсот ";
a %= 100;
}
if ((a / 10) % 10)
{
if ((a / 10) % 10 == 2) cout << "двадцать ";
else if ((a / 10) % 10 == 3) cout << "тридцать ";
else if ((a / 10) % 10 == 4) cout << "сорок ";
else if ((a / 10) % 10 == 5) cout << "пятьдесят ";
else if ((a / 10) % 10 == 6) cout << "шестьдесят ";
else if ((a / 10) % 10 == 7) cout << "семьдесят ";
else if ((a / 10) % 10 == 8) cout << "восемьдесят ";
else if ((a / 10) % 10 == 9) cout << "девяносто ";
else if ((a / 10) % 10 == 1)
{
a %= 10;
if (a == 0) cout << "десять ";
else if (a == 1) cout << "одиннадцать ";
else if (a == 2) cout << "двенадцать ";
else if (a == 3) cout << "тринадцать ";
else if (a == 4) cout << "четырнадцать ";
else if (a == 5) cout << "пятнадцать ";
else if (a == 6) cout << "шестнадцать ";
else if (a == 7) cout << "семнадцать ";
else if (a == 8) cout << "восемнадцать ";
else if (a == 9) cout << "девятнадцать ";
cout <= 2 && a % 10 <= 4) cout <= 5 && a % 10 <= 9 || a == 0) cout << "ов";
cout << " США\n";
return 0;
}
a %= 10;
}
if (a)
{
if (a == 1) cout << "один ";
else if (a == 2) cout << "два ";
else if (a == 3) cout << "три ";
else if (a == 4) cout << "четыре ";
else if (a == 5) cout << "пять ";
else if (a == 6) cout << "шесть ";
else if (a == 7) cout << "семь ";
else if (a == 8) cout << "восемь ";
else cout << "девять ";
}
cout <= 2 && a % 10 <= 4) cout <= 5 && a % 10 <= 9 || a == 0) cout << "ов";
cout << " США\n";
}
else cout << "неверная сумма, повторите ввод \n";
return 0;
}
it turned out to be a mess. how to delete text in a comment without losing data?
#include
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system(“pause”) or input loop */
int main(int argc, char** argv) {
int firstValue;
int secondValue;
cout <> firstValue;
if (firstValue > 9)
{
cout << "\nyou must enter value from 1 to 9\n";
}
else if (firstValue < 1)
{
cout << "\nyou must enter value from 1 to 9\n";
}
cout <> secondValue;
if (secondValue > 9)
{
cout << "\nyou must enter value from 1 to 9\n";
}
else if (secondValue < 1)
{
cout <<"\nyou must enter value from 1 to 9\n";
}
int userAnswer;
int rightAnswer;
rightAnswer = firstValue * secondValue;
cout << firstValue << " * " << secondValue <> userAnswer;
if (userAnswer==rightAnswer)
{
cout << "\nAnswer is right!\n";
}
else
{
cout << "\nYou lost! Right answer is: " << rightAnswer << "\n";
}
return 0;
}