The differences between languages…

I’ve been learning how a few different languages can do the same task, so decided to put up the examples below.

#!/usr/bin/python

number = 5
counter = 1
while (counter <=10):
    if counter < number:
        print (counter, ' is less than ', number)
    elif counter == number:
        print (counter, ' equals ', number)
    else:
        print (counter, ' is greater than ', number)
    counter = counter + 1
Code language: Python (python)
#powershell

$numValue = @(1..10)
$counter = 0

while ($counter -lt $numValue.length){
if ($numValue[$counter] -lt 5){
    write-host "Less than`n"
}
elseif ($numValue[$counter] -eq 5) {
    write-host "Equal`n"
}
else {
    write-host "Greater than`n"
}
$counter += 1
}Code language: PowerShell (powershell)
//C++
#include <iostream>
using namespace std;

int main()
{
    int counter = 1;
    while (counter <= 10) {
        if (counter > 5) { cout << "Greater than\n"; }
        else if (counter == 5) { cout << "Equal\n"; }
        else { cout << "Less than\n"; }
        counter++;
    }
    system("pause>0");
}

Code language: C++ (cpp)

Getting past the basics…

I’ve been watching a C++ tutorial series on Youtube lately, and decided to take some of the basic knowledge that I had of functions, and go into more advanced functions. I was so happy to finally be able to set up a function in an external file, and then pass a variable to that function, and have it be used. Next step will be to manipulate that variable, and pass it back to the main program.

// FunctionExample.cpp : This file contains the 'main' function. Program execution begins and ends there.

#include <iostream>
#include "functions.h"

using std::string;
using std::cout;
using std::cin;
using std::endl;

string name;

int main()
{
    cout << "Please enter your name: ";
    cin >> name;
    function1(name);

    system("pause>0");
}

Code language: C++ (cpp)
//functions.h - This file contains functions declarations for the related cpp file.
#pragma once
int function1(const std::string& name);
Code language: C++ (cpp)
//functions.cpp - User defined functions to be called in the main file.

#include <iostream>
#include "functions.h"

using std::string;
using std::cout;
using std::cin;
using std::endl;

int function1(const string& name)
{
    cout << "Hello " << name << ".";

    return 0;
}
Code language: C++ (cpp)

Hello world!

This felt appropriate…

#include <iostream>
using std::cout;
int main()
  {
    std::cout << "Hello, World!\n";
    return 0;
  }
Code language: C++ (cpp)