From 99aa3e4c7207d71adda1bc66d8f47a587e3e7cec Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Feb 2015 06:48:45 -0800 Subject: [PATCH] sdfaf --- Lab2_1.cpp | 41 ++++++++++++++++++++++++++++++++++++++++ Lab2_2.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ Lab2_3.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 Lab2_1.cpp create mode 100644 Lab2_2.cpp create mode 100644 Lab2_3.cpp diff --git a/Lab2_1.cpp b/Lab2_1.cpp new file mode 100644 index 0000000..2192fc5 --- /dev/null +++ b/Lab2_1.cpp @@ -0,0 +1,41 @@ +// Jacob Steiner= +// 1/23/15 +// lab2_1 + +/* +Pseudocode +flip a coin 100 times and print the user the number of heads +*/ + +#include "stdafx.h" +#include +#include +#include + +using namespace std; + +int _tmain(int argc, _TCHAR* argv[]) +{ + srand(time(NULL)); + int heads = 0; + int tails = 0; + int flip; + for (int i = 0; i < 100; i++){ + + flip = rand() % 2; + if (flip == 0){ + tails++; + } + else { + heads++; + } + + } + + cout << "heads: " << heads << endl; + cout << "tails: " << tails; + getchar(); + getchar(); + return 0; +} + diff --git a/Lab2_2.cpp b/Lab2_2.cpp new file mode 100644 index 0000000..fff1c33 --- /dev/null +++ b/Lab2_2.cpp @@ -0,0 +1,42 @@ +// jacob steiner +// 1/23/15 +// lab2_2 + +/*Pseudocode +generate a number 1 - 100 +have the user guess a number +tell the user if he or she is greater than or less than +if number is right, tell user how many tries it took them +*/ + +#include "stdafx.h" +#include +#include +#include + +using namespace std; + +int _tmain(int argc, _TCHAR* argv[]) +{ + double guess; + double tries = 0; + double number; + cout << "I am thinking of a number 1 - 100, what is it?\n"; + srand(time(NULL)); + number = rand() % 100 + 1; + cin >> guess; + while (guess != number) { + tries++; + if (guess > number){ + cout << "Lower\n"; + } + if (guess < number){ + cout << "higher\n"; + } + cin >> guess; + } + cout << "good, it only took you " << tries << " tries!"; + getchar(); + return 0; +} + diff --git a/Lab2_3.cpp b/Lab2_3.cpp new file mode 100644 index 0000000..ceddda8 --- /dev/null +++ b/Lab2_3.cpp @@ -0,0 +1,55 @@ +// Jacob Steinier +// 1/23/15 +// lab2_3 + +/*pesudocode +allow user to enter the number of dice, the modifier, and the number of sides of their dice +print out the random dice +if all values are 1 +say thanks and exit*/ +#include "stdafx.h" +#include +#include +#include +#include + +using namespace std; + +int _tmain(int argc, _TCHAR* argv[]) +{ + cout << "* WELCOME to *" << endl + << "* Die-Roller! *" << endl + << "*" << endl + << "Instructions: *" << endl + << "To roll, type the number of dice, then the number *" << endl + << "of sides then any modifiers, all separated by *" << endl + << "spaces *" << endl + << "*" << endl + << "like this: 3 6 -1 *" << endl + << "that would mean: *" << endl + << "Roll 3 6-sided dice, and subtract 1 from each die *" << endl + << "*" << endl + << "To exit, enter: 1 1 1 *" << endl + << "ENJOY! * *******************************************************" << endl; + + int dice = 0, side = 0, modifier = 0, stopper = 0; + while (stopper == 0) + { + cout << "\nYour Roll: "; + cin >> dice >> side >> modifier; + if (dice == 1 & side == 1 & modifier == 1){ + stopper = 1; + cout << "Thank you, have a nice day!" << endl; + } + else{ + for (double i = dice; i > 0; i--){ + double v1 = rand() % side + 1; + cout << v1 + modifier << " "; + } + } + } + getchar(); + getchar(); + return 0; +} +