diff --git a/Lab2_1.cpp b/Lab2_1.cpp new file mode 100644 index 0000000..0804c4f --- /dev/null +++ b/Lab2_1.cpp @@ -0,0 +1,33 @@ +// Challenge 1.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" +#include +#include +#include +using namespace std; + +int main() +{ + int heads = 0; + int tails = 0; + int flip = 1; + unsigned int side; + srand(time(0)); + unsigned int coin; + coin = rand() % 2; + do{ + side = rand() % 2; + if (side == 0) + heads++; + else + tails++; + flip++; + } + while (flip <= 100); + cout << "Tails= " << tails << endl; + cout << "Heads= " << heads << endl; + getchar(); + return 0; +} + diff --git a/Lab2_2.cpp b/Lab2_2.cpp new file mode 100644 index 0000000..0eef647 --- /dev/null +++ b/Lab2_2.cpp @@ -0,0 +1,43 @@ +// Lab2_2.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" +#include +#include +#include +using namespace std; + +int main() +{ + srand(static_cast(time(0))); + int secretNumber = rand() % 100 + 1; + int tries = 0; + int guess = 0; + int youWin = 0; + + cout << "\tWelcome to Guess My Number\n\n"; + while (youWin != 1){ + + + cout << "Enter a guess: "; + cin >> guess; + ++tries; + + if (guess > secretNumber) + { + cout << "Lower\n\n"; + } + else if (guess < secretNumber) + { + cout << "Higher\n\n"; + } + else + { + cout << "Thats it! The number was " << secretNumber; + cout << " and it only took you. " << tries << " guesses! "; + youWin++;} + } + getchar(); + getchar(); + return 0; +} \ No newline at end of file diff --git a/Lab2_3.cpp b/Lab2_3.cpp new file mode 100644 index 0000000..9188929 --- /dev/null +++ b/Lab2_3.cpp @@ -0,0 +1,45 @@ +// Lab2_3.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" +#include +#include +#include +using namespace std; + + +int main(){ + //variables + int dice = 0; + int randNum = 0; + int diceTotal = 0; + int sides = 0; + int numDice = 0; + int modifier = 0; + int total = 0; + srand(time(NULL)); + //instructions + cout << "Welcome to Die Roller!\n" << endl; + cout << "Instructions: " << endl; + cout << "To roll, type the number of dice, then the number\n of sides then any modifiers, all separated by\n spaces. \n" << endl; + cout << "like this: 3 6 -1" << endl; + cout << "that would mean: " << endl; + cout << "Roll 3 6-sided dice, and subtract 1 from each die\n" << endl; + cout << "To exit enter: 1 1 1" << endl; + cout << "ENJOY! *******************************************\n" << endl; + + cout << "Your Roll: "; + cin >> numDice; + cin >> sides; + cin >> modifier; + dice = rand() % sides + 1; + + + + + + getchar(); + getchar(); + return 0; +} +