Archive for the ‘C++’ Category

Linux, CentOS, Redhat G++ compiler and rand() / random function

Tuesday, November 18th, 2014

If you are using the G++ compiler in Linux, CentOS, or Redhat there are a couple of steps to adding a random number generator to any project.

  1. Include the precompile library: #include <stdlib.h>
  2. Use the function and add seeding: first_number = rand()%6 +1);

The basic function in C++ for the G++ compiler in Linux looks like this:

#include <iostream>

#include <stdlib.h>

int main()


int first_number = rand()%6 +1;

std::cout << first_number;

return (0);


Starting a console application in Microsoft Visual C++ 2010 Express

Tuesday, November 11th, 2014

Starting a Microsoft Visual C++ Studio Console Application

  1. Open Microsoft Visual C++ 2010 Express
  2. In the menu go to File – New – Project
  3. Click on Visual C++ and highlight Win32 Console Application
  4. Give the new project a name, default directory, and Solution Name
  5. Click OK and another GUI will pop-up
  6. On the Welcome to the Win32 Application Wizard click Next >
  7. On the Application Settings remove the check box from Precompiled Header and check Empty
  8. Click Finish
  9. When the new project opens right click on Source Files
  10. Go to AddNew Item…
  11. When the wizard opens highlight C++ File (.cpp) and give it the name of main.cpp
  12. Click Add
  13. Enter the following in the main.cpp file

          #include <iostream>

           int main()


               return 0;


Place your code after the first curly brace and before the return 0; to get started. Happy coding.


c++ lack jacks game for beginners in cmpsc 121

Tuesday, October 1st, 2013

This is a beginners game of lackjacks that does not use any functions, arrays, or pointers. This is an excellent project to get to know the basics of C++ since you will be using variables, conditional statements, loops, and basic console I/O (input/output). This is a Windows 32 bit console application, so you should be able to paste this code into a blank project that you added a source page.