ПК загадал число от 1 до 10 отгадать его с 3 попыток.
Answers & Comments
Nata9911
Язык C++. #include <iostream> #include <stdlib.h> using namespace std; int main () { int b = 0; int c = 1; int min = 1; int max = 10; srand ( time(NULL) ); int n = min + rand() % (max - min); do{ cout << "Guess the number: " << endl; cin >> b; ++c; if (c > 3) return 3; } while (b != n); cout << "You are right!" << endl; }
Answers & Comments
#include <iostream>
#include <stdlib.h>
using namespace std;
int main () {
int b = 0;
int c = 1;
int min = 1;
int max = 10;
srand ( time(NULL) );
int n = min + rand() % (max - min);
do{
cout << "Guess the number: " << endl;
cin >> b;
++c;
if (c > 3)
return 3;
}
while (b != n);
cout << "You are right!" << endl;
}