Posts

Showing posts from September, 2019

Old School C++ guess the number game

It's been a while since I blogged but I've got some old fashioned code I've updated using the latest versions. This is some C++ code for a simple guessing game. You get 10 tries to guess a number between 1 and 100. The game picks the number randomly and tells you if you've guessed to low, to high, or correctly. This is written using the newer C++ 11 standard so you'll notice some weird stuff with the random number generating. I will post some links to this below. #include <iostream> #include <random> using namespace std; int main() { random_device randomDevice; mt19937 mt(randomDevice()); uniform_real_distribution<double> dist(1.0, 100.0); int numberOfTries = 0; int numberToGuess = dist(mt); int maxNumberOfTries = 10; int currentGuess = 0; bool wonGame = false; cout << "Welcome to guess the number" << endl << end…