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
33 changes: 33 additions & 0 deletions Lab2_1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Challenge 1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <ctime>
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;
}

43 changes: 43 additions & 0 deletions Lab2_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Lab2_2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <ctime>
using namespace std;

int main()
{
srand(static_cast<unsigned int>(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;
}
45 changes: 45 additions & 0 deletions Lab2_3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Lab2_3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <ctime>
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;
}