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
35 changes: 35 additions & 0 deletions Lab2_1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/****************
* Lab2_1.cpp *
* By: Zach Golik *
* Date: 1/23/15 *
****************/

#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h> //rand, srand//
#include <time.h>
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;
}

42 changes: 42 additions & 0 deletions Lab2_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************
* Lab2_2.cpp *
* By: Zach Golik *
* Date: 1/27/15 *
****************/

#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
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;
}
Binary file added Lab2_3.cpp.lnk
Binary file not shown.