Tuesday, December 11, 2012

A Free On-Line C/C++ Compiler

For those who like programming in C or C++, this is a site where you can register for free and use their compiler. You can also view tutorials and sample programs. This site also has a forum.

BotSkool: C and C++ Free On Line Compiler

Sunday, December 2, 2012

Microsoft Small Basic: A Very Simple Slot Machine Program

Here is a simple slot machine program that uses text boxes to display the three numbers. It also uses the timer command. 

'Create a very simple slot machine game
GraphicsWindow.Show()
GraphicsWindow.Title = "A Very Simple Slot Machine Game"
'Add Text Boxes
TextBoxOne = Controls.AddTextBox(30,30)
TextBoxTwo = Controls.AddTextBox(30,70)
TextBoxThree = Controls.AddTextBox(30,110)
'Add Button for rolling them
RollButton= Controls.AddButton("Roll 'em",30,150)
'Display the word Blank in each text bos
Controls.SetTextBoxText(TextBoxOne,"Blank")
Controls.SetTextBoxText(TextBoxTwo,"Blank")
Controls.SetTextBoxText(TextBoxThree,"Blank")
'When Button is pressed, call RollEmSub
Controls.ButtonClicked = RollEmSub

Sub RollEmSub
  'Generate random number between 1 and 3 for each text box
  Controls.SetTextBoxText(TextBoxOne, Math.GetRandomNumber(3))
  Controls.SetTextBoxText(TextBoxTwo, Math.GetRandomNumber(3))
  Controls.SetTextBoxText(TextBoxThree, Math.GetRandomNumber(3))
  'Read each random number
  TextOne = Controls.GetTextBoxText(TextBoxOne)
  TextTwo = Controls.GetTextBoxText(TextBoxTwo)
  TextThree = Controls.GetTextBoxText(TextBoxThree)
  'Compare random numbers
  If TextOne = TextTwo Then
    If TextTwo = TextThree Then
      'Display You Win
      Controls.SetButtonCaption(RollButton,"You Win!")
      Controls.ButtonClicked = DoNothingSub
      'Set delay timer for 20 seconds
      Timer.Interval = 2000
      'When timer expires call EndDelaySub
      Timer.Tick = EndDelaySub
   EndIf
 EndIf
EndSub

Sub EndDelaySub
  Controls.SetButtonCaption(RollButton,"Game over!")
       'Set delay timer for 20 seconds
      Timer.Interval = 2000
      'When timer expires call EndProgramSub
      Timer.Tick = EndProgramSub
EndSub

Sub DoNothingSub
EndSub

Sub EndProgramSub
  Program.End()
EndSub




Saturday, December 1, 2012

ISO C++ Standard 2011

A new ISO Standard for C++ was issued in 2011 and has been implemented in the latest C++ compilers.  I searched for an explanation of this standard after trying to compile a short C++ program that used
a structure containing a character string.

The compiler reported an error for both these statements:
char* mystring = "John";
string mystring = "John";
The error stated that ISO prohibited the initiation of a constant string.

There are still a lot of C++ books and a lot of C++ tutorials that implement this old style of initiating strings.  And this is fine for people working with old compilers. However people working with new compilers or free on-line compilers will experience difficulties with the two C++ statements above as well as in other C++ statements.

I found a C++11 on-line reference at

C++11 Reference

The ISO 2011 C++ Standard costs about $30.00 to download. So I searched further and found a ISO 2011 C++ FAQ for which I provide the link below:

C++11 - the new ISO C++ standard