From 6f7f5d0bc07c573447d8b9b81c954f92cd638508 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Jan 2015 01:22:17 -0800 Subject: [PATCH] new file: Lab2_1.cpp new file: Lab2_2.cpp new file: Lab2_3.cpp --- Lab2_1.cpp | 43 +++++++++++++++++++++++++++++++++++ Lab2_2.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Lab2_3.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 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..014749e --- /dev/null +++ b/Lab2_1.cpp @@ -0,0 +1,43 @@ +/************************** +* Cpp_Lab_02 * +* Author: Alton Stillwell * +* Challenge 1 * +*************************** +* Prompt the user to start* +* then have a random num. * +* (0 or 1) generated and * +* set to 'coin', increase * +* count by 1. Do this 100 * +* times, then display the * +* results of each side * +**************************/ +#include "stdafx.h" +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + int count = 0; + int heads = 0; + int tails = 0; + int coin = 0; + srand(time(NULL)); + while (count < 100){ + coin = rand() % 2; + if (coin == 0){ + tails += 1; + } + else if (coin == 1){ + heads += 1; + } + count += 1; + } + cout << "Tails: " << tails << endl; + cout << "Heads: " << heads << endl; + cin.ignore(); + return 0; +} + diff --git a/Lab2_2.cpp b/Lab2_2.cpp new file mode 100644 index 0000000..6f2670f --- /dev/null +++ b/Lab2_2.cpp @@ -0,0 +1,66 @@ +/***************************** +* Cpp_Lab_02 ~~~ Challenge 2 * +* Author: Alton Stillwell * +* Date: 1/23/15 * +****************************** +* Have an intro message, then* +* initilize the variables for* +* theNumber, guess, and tries* +* Afterwards set theNumber * +* to a(get this) a random num* +* Have the user guess and * +* have the program respond * +* accordingly. In the end * +* give the amount of tries * +* and have the user press * +* to exit * +*****************************/ +#include "stdafx.h" +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + // Intro text + cout << " Welome 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; + + // initialize values + int theNumber = 0; + int guess = 0; + cout << "Enter first guess: "; + cin >> guess; + int tries = 1; + + // generate the random number + srand(time(NULL)); + theNumber = rand() % 101; + + // Guessing loop + while (guess != theNumber){ + if (guess > theNumber){ + cout << "Lower..." << endl; + } + else if (guess < theNumber){ + cout << "Higher..." << endl; + } + cout << "Enter new guess: "; + cin >> guess; + cout << endl; + tries += 1; + } + + // Ending text + cout << endl; + cout << "You guessed it! The number was " << theNumber << endl; + cout << "And it only took you " << tries << " tries!" << endl << endl; + cout << "Press the key to exit."; + cin.ignore(); + cin.ignore(); + return 0; +} + diff --git a/Lab2_3.cpp b/Lab2_3.cpp new file mode 100644 index 0000000..a6b6264 --- /dev/null +++ b/Lab2_3.cpp @@ -0,0 +1,59 @@ +/************************** +* Cpp_Lab2_3 * +* Author: Alton Stillwell * +* Date: 1/27/15 * +**************************/ +#include "stdafx.h" +#include +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + // Intro text + cout << "Welcome to the" << endl; + cout << "Super Amazing Die-Roller!" << endl << endl; + cout << "Instructions:" << endl; + cout << "To roll, type the number of dice, then the number" << endl; + cout << "of sides then any modifiers, all separated by spaces." << endl; + cout << "Example: 3 6 -1" << endl; + cout << "Which means:" << endl; + cout << "Roll 3 6-sided dice, and subtract 1 from each die" << endl << endl; + cout << "To exit, enter 1 at the side setter. Ie: 4 1 5" << endl << endl; + cout << "*****************************************" << endl << endl; + //Initilize variables + int numDice = 0; //will carry the number of dice + int numSide = 0;//will carry the number of sides the dice has + int mod = 0;//will hold a modifier to either add or subtract from the actuall roll + int choice[3] = { 0, 0, 0 };//initilize the array + srand(time(NULL)); + //Game Loop + cout << "Enter values: "; + for (int i = 0; i < 3; i++){ + cin >> choice[i]; + } + while (choice[1] != 1){ + numDice = choice[0]; + numSide = choice[1]; + mod = choice[2]; + cout << "Roll " << numDice << "-" << numSide << " sided dice, with a modifier of " << mod << "." << endl; + cout << "Results: "; + for (numDice; numDice > 0; numDice--){ + cout << (rand() % numSide + mod + 1) << " "; + } + cout << endl << endl; + cout << "Enter values: "; + for (int i = 0; i < 3; i++){ + cin >> choice[i]; + } + } + //Ending Text + cout << endl << endl; + cout << "Press to exit"; + cin.ignore(); + cin.ignore(); + return 0; +} \ No newline at end of file