Tag: code

Simple C++ lottery program @KTSI

Here is a simple C++ lottery program done for the KTSI.

#include <iostream>
#include <cstdlib>
 
using namespace std;
 
int main (int argc, char * const argv[]) {
 
	int numberCount;
	int maxNumbers;
 
	cout << "Lottery Game" << endl << "=================================" << endl;
	cout << "How many Lottery Numbers = ";
	cin >> numberCount;
	cout << "from 1 to ? ";
	cin >> maxNumbers;
	cout << "You have chosen " << numberCount << " Lottery Numbers from 1 to " << maxNumbers << endl;
 
	int lotteryNumbers[numberCount];
	int i, j;
	bool newNumber;
 
	srand(0);
	for(i=0; i<numberCount; i++) // get numbers
	{
		do  
		{   // Check Random
			lotteryNumbers[i] = rand() % maxNumbers + 1;
			newNumber = true;
			for (j=0; j<i; j++)
			{  
				if (lotteryNumbers[j]==lotteryNumbers[i])
				{ // Check for existing numbers
					newNumber = false;
				}
			}
		} while (!newNumber);
	}
	for (i=0; i<numberCount; i++)
	{
		cout << lotteryNumbers[i] << " ";
	}
	cout << endl;
}


PowerShell

PowerShell: Count your Code lines

After Coding some lines in a lot of different files you wanna know how much lines you have coded. There are two (I am sure there are even more) ways to do that. The first one is to get the content of the files (Get-Content) and count the lines in there. With the Select-String cmdlet, you can count your code lines in a file or script using PowerShell.

The other way and the faster way is with Select-String:

(Get-ChildItem -Include *.ps1 -Recurse | Select-String -pattern .).Count

You can find more about Select-String on Microsoft Docs.

I hope this gives you an idea how you can count your lines of codes in PowerShell. Also have a look at at my blog post about how to install PowerShell 6 and PowerShell 7. If you have question, let me know in the comments.



Powershell Header

Powershell: if Statement basics

The if Statement is pretty important if you are creating PowerShell scripts. So I created this post to get some basic information here.

First, the syntax with a simple if:

if (condition) {do}

You can also use elseif and else:

if (condition) {do}
elseif (condition) {do}
else {do}

A simple if could look like this:


if ($varibale -eq "1") {
Write-Host "Yes variable is 1"
}

Comparison Operators:

  • Equal to: -eq
  • Less than: -lt
  • Greater than: -gt
  • Greater than or Eqaul to: -ge
  • Less than or equal to: -le
  • Not equal to: -ne

You can also check case-sensitive by adding a “c” to the operator. “-eq” would be “-ceq

Logical Operators:

  • Not -not
  • Not !
  • And -and
  • Or -or

So you can simply add multiple conditions:


if ($varibale -eq "1" -or $varibale -eq "2") {
Write-Host "Varibale is 1 or 2"
}