Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Lab2_1.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
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;
}

66 changes: 66 additions & 0 deletions Lab2_2.cpp
Original file line number Diff line number Diff line change
@@ -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 *
* <enter> to exit *
*****************************/
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <string>
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 <enter> key to exit.";
cin.ignore();
cin.ignore();
return 0;
}

59 changes: 59 additions & 0 deletions Lab2_3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**************************
* Cpp_Lab2_3 *
* Author: Alton Stillwell *
* Date: 1/27/15 *
**************************/
#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sstream>
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 <enter> to exit";
cin.ignore();
cin.ignore();
return 0;
}