beep boop

This commit is contained in:
left_adjoint 2024-02-14 17:25:10 -08:00
parent d8523a7e7b
commit e66ddf7f42
2 changed files with 105 additions and 0 deletions

47
flipgame.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <iostream>
#include <stdlib.h>
using namespace std;
// change this to add a variable that counts
// how many times you were right
int main(){
string input;
int guess = -1;
int wins = 0;
int games = 0;
srand(time(0));
int coin = -1;
//flip the coin
coin = rand() % 2;
cout << "Guess heads or tails: ";
cin >> input;
while(input != "quit"){
if(input == "heads"){
guess = 0;
games = games + 1;
}
else if(input == "tails"){
guess = 1;
games = games + 1;
}
else {
guess = -1;
}
if(guess == coin){
cout << "You were right" << endl;
wins = wins + 1;
}
else if(guess != -1){
cout << "Nope" << endl;
}
coin = rand() % 2;
cout << "Guess heads or tails: ";
cin >> input;
}
cout << "You were right: " << 100*(float)wins/games << "% of the time" << endl;
return 0;
}

58
fun1.cpp Normal file
View File

@ -0,0 +1,58 @@
#include <iostream>
using namespace std;
string asker(string prompt){
string s;
cout << prompt << endl;
cin >> s;
return s;
}
string asker(string askPrompt, string thankPrompt){
string s;
cout << askPrompt << endl;
cin >> s;
cout << thankPrompt << endl;
return s;
}
bool yesOrNo2(string prompt){
string input;
cout << prompt << endl;
cin >> input;
// !(input == "yes" || input == "no")
while(input != "yes" && input != "no"){
cout << prompt << endl;
cin >> input;
}
return (input == "yes");
}
bool yesOrNo(string prompt){
// function should display prompt
// then ask for an answer
// return true if answer == "yes"
// return false otherwise
string input;
cout << prompt << endl;
cin >> input;
if(input == "yes"){
return true;
}
else {
return false;
}
}
int main(){
bool answer = yesOrNo2("Are dogs good?");
if(answer){
cout << "Glad you agree" << endl;
}
else{
cout << "...why?" << endl;
}
return 0;
}