Hello. I've been having some trouble with my recent program. I'm trying to make a computer which calculates a number the user decides secretly for him- or herself. The problem is basically, that because my numbers are integer and not floating point numbers, I'll get my numbers rounded down every so often. Please do help, I'm kinda stuck.
// ovelse.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
int main()
{
usingnamespace std;
cout << "Think of a number between 1 and 100. I will try to guess it." << endl;
cout << "If the number is too high, press h. If the number is too low, press l. If the number is correct, press c." << endl;
int Guess = 50;
staticint Number = 50;
for (int iii=0; ; )
{
cout << "Er " << Guess << " det tal du tænkte på? ";
char Answer;
cin >> Answer;
Number = Number/2;
if (Answer == 'l')
{
Guess = Guess+Number;
}
elseif (Answer == 'h')
{
Guess = Guess-Number;
}
elseif (Answer == 'c')
{
cout << "Jeg gættede rigtigt! Juhuuu...." << endl;
break;
}
}
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}