From 3317d89cbb14609246e23f3f909b42fba13bbdb6 Mon Sep 17 00:00:00 2001 From: h45-taylor <harvey.taylor3@live.uwe.ac.uk> Date: Tue, 12 Dec 2023 12:08:46 +0000 Subject: [PATCH] created new application that shows probability of the random number in my program --- .gitignore | 3 ++- README.md | 6 ++---- rnd.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 rnd.cpp diff --git a/.gitignore b/.gitignore index 586e389..7dc6c63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ .vscode -a.out \ No newline at end of file +a.out +rnd \ No newline at end of file diff --git a/README.md b/README.md index 97d7a4d..201b4c5 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,9 @@ * You can use w/a/s/d or W/A/S/D to control the game. -* If there is no empty cells left with no valid moves then the game will end.. - -## The Aim -The aim of the game is to get one of the tiles upto a score of 2048 by combining other tiles. +* If there is no empty cells left with no valid moves then the game will end. +* If you get one of the cells to 2048 you win. ## The functions in depth diff --git a/rnd.cpp b/rnd.cpp new file mode 100644 index 0000000..58c3d57 --- /dev/null +++ b/rnd.cpp @@ -0,0 +1,40 @@ +#include <iostream> +#include <ctime> +using namespace std; + +int main() { + +int avg2 = 0; +int avg4 = 0; + +int Loop; + +srand(time(0)); + +for (Loop = 0; Loop < 100; Loop++) +{ + +int random = rand(); +cout << random << endl; + +int randomaftr = rand() % 2; +cout << randomaftr << endl; + +int randpone = randomaftr + 1; +cout << randpone << endl; + +int randmtwo = randpone * 2; +cout << randmtwo << endl; + +if (randmtwo == 2) +{ + avg2++; +} +if (randmtwo == 4) +{ + avg4++; +} +} + +cout << "After " << Loop << " loops, We have resulted in 2 a total of " << avg2 << " times and 4 " << avg4 << " times."; +} \ No newline at end of file -- GitLab