Tips needed for a guessing progam

Hey, im newer to programing and c++ i just want some tips on how to start this program.the program is to have the user guess a number, then have the program orig guess 50, and then have the user say higher or lower till the progam guesses the correct number. i would like to do this mathmatically. Im not asking for the entire answer. just some tips. I originally tried to go through every senaryo. for example;
guesses = 50
higher
guess = 75
higher
guess = 90
higher
guess = 95
lower
guess = 93
correct.
but this type of programming takes forever and there is alot of room for error.
Hi, so you want to create AI like program :D

I'm not shore what do you want? a program which will guess the number that user knows or will user guess a number which program know?

here is an incomplete code which does not work but it may give an idea on how to achive your task:

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
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
	int guess = 50;
	int high = 2;
	int low = 2;
	do {
		bool input, INCORECT = true;
		cin >> input;
		switch (input)
		{
		case true: //higher 
			guess += guess / high;
			++high;
			low = 2;
			break;
		case false: //lower
			guess -= guess / low;
			++low;
			high = 2;
			break;
		default:
			cerr << "wrong input";
	}while(INCORECT);

	cin.ignore();
	return 0;
}


If you want the program to guess the answer, you can use dichotomia:
say the max number is MAX, the min is MIN.
the computer compute GUESS = MIN + (MAX - MIN) / 2
Then if the user say higher MIN = GUESS else MAX = GUESS...
until MIN is equal to MAX
I give you the idea, try to make this an algorithm
Topic archived. No new replies allowed.