Given such a task.

The program "conceives" a number in the range from 1 to 10 and prompts the user to guess the number of 5 attempts.

Program:

#include <vcl.h> #include <iostream.h> #include <conio.h> #include <stdlib.h> char *Rus(const char *text); { srand(time(0)); int a; // задуманное число int b; // число которое вводит пользователь int c = 5; // число попыток a = rand() % 10; do { c--; cout << Rus(" Введите число: "); cin >> b; } while (c != 0 || b != a) if (c == 0 && b != a) cout << Rus(" у вас не осталось попытки, вы проиграли "); else if (a == b) cout << Rus(" вы победили "); getch(); } char bufRus[256]; char *Rus(const char *text) { CharToOem(text, bufRus); return bufRus; } } 

But the program gives errors. Help me please.

  • one
    and what errors does the program produce? You do not praise ";" after while . And what do you do with the srand function before the declaration of variables? - margosh

1 answer 1

The error was in the condition on the cycle: it is necessary that both conditions are fulfilled (instead of the operator "or", the operator is needed "and" &&). The Rus function does not work for me, so I rewrote it with the Latin alphabet.

 #include <iostream> #include <conio.h> #include <stdlib.h> using namespace std; int main() { srand(time(0)); int a; int b; int c = 5; a = rand() % 10; do { c--; cout << "Vvedi chislo: "; cin >> b; } while ((c != 0) && (b != a)); if (c == 0 && b != a) cout << "Game over!"; else if (a == b) cout << "Vi pobedili."; getch(); } 

Code rules using the Dev C ++ compiler.

  • Thank you so much. I got it. - IvAn