`//This will return the quotient of the equationint quotient = 11 / 1;//This is the remainer and will be equal to 1int remainder = 11 % 10;`

This has some interesting uses for example it is an easy way to check if a number is even or odd or rather if it is divisible by any number because if the quotient equals zero then it is divisible by that number

`//Check even or oddif (num % 2 == 0) return "Is even"else return "Not even"`

Okay so I've talked about the modulus operator now what does this lab want us to do? It asks a few questions it wants us to ask the user for a four digit number, then to calculate the sum of those digits and then the sum of the digits of the sum and then the sum of the digits of the sum of the digits of the sum. That last part is confusing but is a direct quote from the lab. Let's look at an expected output to get a better idea of what we are being asked.

`Please enter a four digit number : 7859The sum of the digits is : 0029The sum of the digits of the sum is : 0011The sum of the digits of the sum of the digits is : 0002`

Alright now that we can see what we are solving, how can the modulus operator be applied here. Well we can combine the division operator and the modulus. Say for example 7859 and we want to pop that 9 off the end?

`int num = 7859int fourthDigit = num%10 // this equals 9int thirdDigit = num/10 % 10 // this equals 5int secondDigit = num/100 % 10 // this equals 8int firstDigit = num/1000 // this equals 7`

In the above code we combine the two. For the fourth digit we can simply use the modulus operator to get the last digit with %10. If we look at the math it would be a quotient of 785 with a remainder of 9. Using division we can cut the number down in a sense. For example when we divide 7859/10 we get the 785 we just talked about but what happens if we then do %10 again? We get the 5 off the end. Repeating this step again for the second digit but instead dividing by 100. Something interesting happens when we get to the end of out number though. We could continue the pattern with 7859/1000%10 but if we look at that we realize it is unnecessary because 7859/1000 = 7 which is already the answer we need.

Putting all of this all together with what we learning in activity 2 will look something like this.

` int sum, num1, num2, num3, num4; cout << "Please enter a 4 digit integer." << endl; cin >> sum; num4 = sum % 10; num3 = sum / 10 % 10; num2 = sum / 100 % 10; num1 = sum / 1000; sum = num1 + num2 + num3 + num4; cout << "Sum of the digits: " << num1 << " + " << num2 << " + " << num3 << " + " << num4 << " = " << sum << endl; num4 = sum % 10; num3 = sum / 10 % 10; num2 = sum / 100 % 10; num1 = sum / 1000; sum = num1 + num2 + num3 + num4; cout << "Sum of the digits of the sum: " << num1 << " + " << num2 << " + " << num3 << " + " << num4 << " = " << sum << endl; num4 = sum % 10; num3 = sum / 10 % 10; num2 = sum / 100 % 10; num1 = sum / 1000; sum = num1 + num2 + num3 + num4; cout << "Sum of the digits of the sum of the digits of the sum: " << num1 << " + " << num2 << " + " << num3 << " + " << num4 << " = " << sum << endl;`

This could be made a lot better if we were allowed to use functions but as mentioned before this class has limitations in place and one of them prevents the use of functions.

This activity is a great example of how a simple operator combined with a little creativity and logic can solve problems effectively and efficiently.

]]>Alright now that I have all the caveats out of the way let's talk about the task given and initial thoughts of how to achieve this problem. The problem asks us to accept 5 numbers from a user and print the average of those numbers. This is simple and intended for you to dip your toes into working with the input and output buffers. Another important thing to note is for the sake of simplicity I will be omitting any error catching and will expect proper inputs into the program. This program is also only supposed to run once and has no looping structure.

First we need to ask the user to enter numbers by printing something to the screen and then take an input from the user. For printing our prompt to the user we will push a string to the Cout buffer. There are two methods that come to mind for accepting input, Cin and getline(). For this we will use Cin. We also need to declare variables to handle the user input and to make the code more readable I declared another variable we will use to store the average.

`//The variables we will use to store the users inputsint a, b, c, d, e;//The variable we will use to store the averagedouble average = 0.f;//Ask the user our prompt by inserting a string into the output buffer//using the << operator.cout << "Please enter 5 seperate integers seperated by a space.\n";//This line is how we accept input from the user. Because of the spaces//between characters the >> operator will conviently break up the inputs into//each variable until they are all handled.cin >> a >> b >> c >> d >> e;`

The next step is to average these numbers, store the result in our average variable and return the result in a nice formatted way to the user. We will use push the formatted string to Cout using the << operator.

`//Do the average calulation and store it in averageaverage = (a + b + c + d + e) / 5.f;//Push a string and the average to the output buffer.//By using multiple << operators we can have the effect of a single string//without concatination. endl is another way of inserting a newline character.cout << "The average is " << average << endl;`

A typical run of the program would look something like this when put together.

`Please enter 5 seperate integers seperated by a space.5 1 1 1 4The average is 2.4`

Put together this is not a complex program by any stretch of the imagination but is a good starting point for any beginner looking to learning programming. This is just slightly more complex than a simple hello world program. The source code for all of my projects can be found here on my github.

]]>I've started learning how to code for the first time when I was 15. Oddly enough it was a mod called Computer Craft in Minecraft that started me on this journey. I was hooked quickly. At the time as a kid growing up in a very rural area that still had dial up until I was 15 it seemed almost magical that anyone that wanted to could learn how to code. Everyone around me treated computers like a little black box with zero chance of understanding how they worked but for me it was just an opportunity to learn something unique and challenging.

Fast forward to 19 years old I had stuck with it but mostly was still just programming in LUA for Computer Craft. I experimented a bit with Unity but did not make anything of note. This was however my first interaction with anything besides LUA. It was a bit of a learning curve as LUA is incredibly forgiving although C# itself in retrospect is alway rather easy to write in. At 19 I joined the United States Air Force and served 6 years until last year when I separated. I enjoyed my time and learned a lot but was quite busy. I did during that time learn a fair amount about other languages and work on other projects. I experimented with C++, JavaScript, C#, Java and C. I also moved on to Unreal Engine as my prefered way of experimenting with game design/development.

I am 26 now and going to school full time at Penn State University for Software Engineering. A little late but thanks to my service I am fortunate to have great education benefits. I just finished my first semester and plan to go back and write articles about various classwork that I did related to software engineering and anything I do in the future.

]]>