Answer the question
In order to leave comments, you need to log in
How to repeatedly ask to enter the data until the correct ones are entered?
It seems that some kind of simple cycle is needed, I don’t remember which one. The user enters incorrect data, and the program should constantly ask him to enter the correct ones
Answer the question
In order to leave comments, you need to log in
#include<iostream>
using namespace std;
int main()
{
long long int a;
cout << "Введите пятизначное число: ";
cin >> a;
if(a >= 10000 && a <= 99999)
{
int f = a % 10;
int e = (a / 10) % 10;
int d = (a / 100) % 10;
int c = (a / 1000) % 10;
int b = (a / 10000) % 10;
cout << b << endl;
cout << c << endl;
cout << d << endl;
cout << e << endl;
cout << f << endl;
}
else
{
do
{
cout << "ТЫ ЧЁ ДУРАК БЛЯТЬ?" << endl;
cout << "Христом богом заклинаю, только пятизначные, плес. Пробуй: " << endl;
cin >> a;
if (a >= 10000 && a <= 99999)
{
int f = a % 10;
int e = (a / 10) % 10;
int d = (a / 100) % 10;
int c = (a / 1000) % 10;
int b = (a / 10000) % 10;
cout << "Число номер 1: " << b << endl;
cout << "Число номер 2: " << c << endl;
cout << "Число номер 3: " << d << endl;
cout << "Число номер 4: " << e << endl;
cout << "Число номер 5: " << f << endl;
}
}
while (a > 99999 || a < 10000);
}
return 0;
}
That's not what you're asking.
Any cycle can be used:
for(;;) {...}
while(true) {...}
do {...} while(true)
Works until the user enters the required data. ( Until _a equals 7) . I apologize for the code, I am writing from the phone on the road.
#include <iostream>
using namespace std;
int main() {
int _a;
do
{
cout<<"'Input a: ";
cin>>_a;
}
while(_a!=7);
cout<<"Correct input\n";
}
#include <iostream>
using namespace std;
int main(){
for(int _a; _a!=7; cin>> _a ){
cout<<"'Input a: ";
}
}
#include <iostream>
using namespace std;
struct MyData {
int value;
MyData(int v) : value(v){}
MyData() : value(0){}
};
istream& operator>>(istream& is, MyData& data)
{
is >> data.value;
return is;
}
ostream& operator<<(ostream& os, MyData& data)
{
os << data.value;
return os;
}
bool operator==(const MyData& lh, const MyData& rh)
{
return lh.value == rh.value;
}
bool operator!=(const MyData& lh, const MyData& rh)
{
return !(lh.value == rh.value);
}
MyData try_read_while_not(MyData d, const string& message)
{
MyData val;
while(val != d)
{
cout << message;
cin >> val;
}
return val;
}
int main()
{
MyData correct(42);
MyData val = try_read_while_not(correct, "Введите значение: ");
cout << val;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question