diff --git a/Lab2_1.cpp b/Lab2_1.cpp new file mode 100644 index 0000000..4e474d3 --- /dev/null +++ b/Lab2_1.cpp @@ -0,0 +1,35 @@ +/**************** +* Lab2_1.cpp * +* By: Zach Golik * +* Date: 1/23/15 * + ****************/ + +#include "stdafx.h" +#include +#include +#include +#include //rand, srand// +#include +using namespace std; + +int main(){ + cout << "I am going to flip a coin 100 times"<< endl << + "Then I will tell you how many heads and how many tails I got." << endl; + int i = 0, heads = 0, tails = 0, flip = 0; //Initializing: heads, tails, i(count), flip(random number)// + srand(time(NULL)); //srand// + while (i != 100){ //WHILE LOOP// + flip = rand() % 2; //Random number// + if (flip == 0){ + heads += 1; + } + else if (flip == 1){ + tails += 1; + } + i += 1; + } + cout << "Heads: " << heads << endl; + cout << "Tails: " << tails << endl; + system("pause"); + return 0; +} + diff --git a/Lab2_2.cpp b/Lab2_2.cpp new file mode 100644 index 0000000..f1ace1f --- /dev/null +++ b/Lab2_2.cpp @@ -0,0 +1,42 @@ +/**************** +* Lab2_2.cpp * +* By: Zach Golik * +* Date: 1/27/15 * + ****************/ + +#include "stdafx.h" +#include +#include +#include +#include +#include +using namespace std; + +int main(){ + int number = 0, i = 0, guess = 0; + srand(time(NULL)); + number = rand() % 100 + 1; + cout << "\tWelcome to 'Guess My Number'!" << endl << + "I'm thinking of a number between 1 and 100." << endl << + "Try to guess it in as few attempts as possible." << endl; + cout << "Take a guess: "; + cin >> guess; + while (guess != number){ + if (guess < number){ + cout << "Higher..." << endl; + i += 1; + } + else if (guess > number) { + cout << "Lower..." << endl; + i += 1; + } + cout << "Take a guess: "; + cin >> guess; + } + cout << "You guessed it! The number was " << number << endl << + "And it only took you " << i << " tries!" << endl << endl << + "Press the enter key to exit."; + getchar(); + getchar(); + return 0; +} \ No newline at end of file diff --git a/Lab2_3.cpp.lnk b/Lab2_3.cpp.lnk new file mode 100644 index 0000000..1e720cb Binary files /dev/null and b/Lab2_3.cpp.lnk differ