Did I learn it? #3
DHDucky
Posted on June 16, 2023
ARRAY
If you have been looking at my reference, you would know that I skipped the whole of chapter 10 after Structs and just went to Chapter 11. Well because I saw something I knew about and was too excited: Arrays.
For the most part, I knew everything that Alex - the website dev - covered like: the intialization, sorting, multidimensional arrays and etc. As a proof, here's something:
#include <iostream>
using namespace std;
int inHand[100];
int numCard;
bool overTwentyOne()
{
int Total = 0;
int cntAce = 0;
for (int i = 0; i < numCard; i++){
if (inHand[i] == 74 || inHand[i] == 75 || inHand[i] == 81 ){
Total += 10;
}
else if (inHand[i] == 65){
cntAce++;
continue;
}
Total = Total + inHand[i];
}
if (cntAce == 0 && Total <= 21) return false;
else if (Total <= 21 - cntAce || Total <= 11 - cntAce) return false;
return true;
}
int main()
{
cin >> numCard;
for (int i = 0; i < numCard; i++) cin >> inHand[i];
if (overTwentyOne()) cout << "You are Busted!";
else cout << "You are Good!";
return 0;
}
Just a simple program that checks if you are Busted given a Blackjack hand. But the codes are a bit messy, so I need some more practice. So if you can recommend me some good websites or fix my code will all be much appreciated!
... And I need advices on blog writing too. Thanks!
REFERENCE
Chapter 11.1 - 11.5
Posted on June 16, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.