-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (33 loc) · 941 Bytes
/
main.cpp
File metadata and controls
39 lines (33 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace std;
const int Maximo = 1000;
int main() {
int inf=0, supp=Maximo;
int n=0;
bool achou = false;
int tentativa;
while (! achou) {
tentativa = (inf+supp)/2;
char op;
cout << "Tentativa: " << tentativa << endl;
cout << "Digite: = (se seu número for igual), < (se seu número for menor, > (se for maior): " << endl;
cin >> op;
switch (op) {
case '=':
achou = true;
break;
case '<':
supp = tentativa-1;
break;
case '>':
inf = tentativa + 1;
break;
default:
cout << op << " NÃO é uma opção válida !!!" << endl;
break;
}
n++;
}
cout << "Descobriu seu número (" << tentativa << ") em " << n << " tentativas" << endl;
return 0;
}