From 72c63918ba1fed8e0fde8569ddfb905ef794eb21 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Jan 2015 09:42:59 -0600 Subject: [PATCH] new file: Lab2_1.cpp new file: Lab2_2.cpp new file: Lab2_3.cpp --- Lab2_1.cpp | 38 ++++++++++++++++++++++++++++++++++++ Lab2_2.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ Lab2_3.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 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..0e196c6 --- /dev/null +++ b/Lab2_1.cpp @@ -0,0 +1,38 @@ +// ConsoleApplication17.cpp : Defines the entry point for the console application. +// + +/*Program: Coin Flip +Date: January 23, 2015 +Author: Brianna Melius, with modification by: Zachary Micheal Joseph Anthony Golik and Brandon McCurry +*/ + +#include "stdafx.h" +#include +#include +#include +#include +#include +using namespace std; + +int main(){ + int coin, heads, tails, counter; + heads = 0; + tails = 0; + counter = 0; + srand(time(NULL)); + while (counter != 100){ + coin = rand() % 2; + + if (coin == 0){ + heads++; + } + else if (coin == 1){ + tails++; + } + counter++; + } + cout << "You flipped heads: " << heads << " times!" << endl; + cout << "You flipped tails: " << tails << " times!" << endl; + getchar(); + return 0; +} diff --git a/Lab2_2.cpp b/Lab2_2.cpp new file mode 100644 index 0000000..244bca4 --- /dev/null +++ b/Lab2_2.cpp @@ -0,0 +1,48 @@ +// ConsoleApplication18.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" + + +int _tmain(int argc, _TCHAR* argv[]) +{ + return 0; +} +#include +#include +#include +#include +#include +using namespace std; +int main(){ + int tries, number, guess; + tries = 1; + guess = 0; + cout << "Welcome to 'Guess My Number'!" << endl; + cout << "I'm thinking of a number between 1 and 100." << endl; + cout << "Try to guess it in as few attempts as possible." << endl; + cout << "Take a guess: "; + cin >> guess; + srand(time(0)); + number = rand() % 100 + 1; + while (guess != number){ + if (guess > number){ + cout << "Lower..." << endl; + } + else if (guess < number){ + cout << "Higher..." << endl; + } + cout << "Take a guess: "; + cin >> guess; + tries++; + } + cout << "You guessed it! The number was " << number << endl; + cout << "And it only took you " << tries << " tries!" << endl; + system("pause"); + return 0; + +} + + + + diff --git a/Lab2_3.cpp b/Lab2_3.cpp new file mode 100644 index 0000000..a2f71b6 --- /dev/null +++ b/Lab2_3.cpp @@ -0,0 +1,56 @@ +// ConsoleApplication20.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" +#include +#include +#include +#include +#include +using namespace std; +int main(){ + cout << "*******************************************************" << endl << + "* 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 << + "*******************************************************" << endl; + cout << "Your Roll: "; + int rollArray[3] = { 0, 0, 0 }, diceNum = 0, sideNum = 0, modifiers = 0, results = 0, total = 0; + for (int i = 0; i < 3; i++){ + cin >> rollArray[i]; + } + diceNum = rollArray[0]; + sideNum = rollArray[1]; + modifiers = rollArray[2]; + srand(time(NULL)); + while (diceNum != 1, || sideNum != 1, || modifiers != 1){ + for (int i = 0; i < diceNum; i++){ + total += ((rand() % sideNum + 1;) + modifiers); + } + cout << "Total: " << total; + cout << "Your Roll: "; + int rollArray[3] = { 0, 0, 0 }, diceNum = 0, sideNum = 0, modifiers = 0, results = 0, total = 0; + for (int i = 0; i < 3; i++){ + cin >> rollArray[i]; + } + diceNum = rollArray[0]; + sideNum = rollArray[1]; + modifiers = rollArray[2]; + getchar(); + } + cout << "Thank you, Have a nice day."; + getchar(); + getchar(); +} +