From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp (limited to 'Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp') diff --git a/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp new file mode 100644 index 0000000..35796d5 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_2/main.cpp @@ -0,0 +1,81 @@ +// Programmieren 1, Praktikum 3, Aufgabe 2 +// Sven Eisenhauer +// 12.11.2004 +// +// file: main.cpp +// +// purpose: roll 2 dice 6000 times and build a table, how often each possible sum occured +// +// +// +// +#include +using std::cin; +using std::cout; +using std::endl; + +#include +#include + +int rollDice(void); + +int main () +{ + int stats[13] = {0}; + + srand(time(0)); + + for (int Counter=0;Counter <= 6000;Counter++) + { + /* switch (rollDice()) + { + case 2: + stats[0]++; + break; + case 3: + stats[1]++; + break; + case 4: + stats[2]++; + break; + case 5: + stats[3]++; + break; + case 6: + stats[4]++; + break; + case 7: + stats[5]++; + break; + case 8: + stats[6]++; + break; + case 9: + stats[7]++; + break; + case 10: + stats[8]++; + break; + case 11: + stats[9]++; + break; + case 12: + stats[10]++; + break; + default: + cout << "Uuups... we should never get here..."; + }*/ + ++stats[rollDice()]; + } + for (int i=2;i<=12;i++) + { + cout << endl << i << ": " << stats[i]; + } + cout << endl; + return 0; +} + +int rollDice(void) +{ + return (( 1 + (rand() % 6)) + ( 1 + (rand() % 6))); +} \ No newline at end of file -- cgit v1.2.3