dare599z 16 Newbie Poster

I'm not sure which version of Visual Studio you are using, but they should be similar. in 12 Beta, click on of the radio buttons and go to the Events Tab (should be a tab next to the Properties tab where you change the text and whatnot). Right click the "CheckChanged" event and press Reset. That will un-associate the event with your method. Then, scroll down to the Validated event and double click it. This will (at least in VS12B), create a method stub for the radioButton_Validated event. This is where you can put the code. Here is the project file for the version I made, if you want to take a look at it. Once again, this is using VS 12 Beta, so I'm not sure if it's compatible with your version.

project file in zip

dare599z 16 Newbie Poster

I actually just noticed something interesting: putting the message boxes, they pop up two at a time when a box is clicked, once at start-up, and once on exit. (I made a version of this game really quick.) Changing the event from CheckChanged to Validated helped eliminate the double boxes. Something is wacky with the way the radio buttons CheckChanged event is called, so I'd switch to Validated. Even then, though, the box pops up on exit of the application. Some kind of internal event handling I suppose.

In any case, here's the Form of the game (tooltip included as well), followed by the simple logic.

namespace GuessingGame
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.radioButton1 = new System.Windows.Forms.RadioButton();
            this.radioButton2 = new System.Windows.Forms.RadioButton();
            this.radioButton3 = new System.Windows.Forms.RadioButton();
            this.radioButton4 = new System.Windows.Forms.RadioButton();
            this.radioButton5 = new System.Windows.Forms.RadioButton();
            this.label1 = new System.Windows.Forms.Label();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.SuspendLayout();
            // 
            // radioButton1
            // 
            this.radioButton1.AutoSize = true;
            this.radioButton1.Location = new System.Drawing.Point(35, 42);
            this.radioButton1.Name = "radioButton1";
            this.radioButton1.Size = new …
dare599z 16 Newbie Poster

I would do away with all the conversion work you have going on in Convert.ToInt16(numGuess5.Text) and the others because it's just unnecessary since they're static.

private void numGuess2_CheckedChanged(object sender, EventArgs e)
    {
        if (correctAnswer == 2)
            this.lblOutput.Text = "correct answer";
        else
            this.lblOutput.Text = "incorrect answer";
    }

and do that for all the others-- 1, 3, 4, 5.
Even easier:

     private void numGuess2_CheckChanged(object sender, EventArgs e) 
     {
         if (correctAnswer == 2) MessageBox.Show("Correct!");
         else MessageBox.Show("Incorrect :(");
     }

Perhaps it's something about the way those labels work. I'm a beginner as well, so this is just my thoughts.

dare599z 16 Newbie Poster

Hi all!

I'm a beginner to C++ and wanted to try my skill at creating a decimal to binary converter in the console. I tried two different methods, but I failed at both.

My first program was an attempt at being organized and using multiple functions and snaking the output through each of them to reach the binary value. The premise was simple(or so I thought): Get decimal, check for the highest degree of 2 allowed in the value, record the value as a '1' in an array. Then it should subtract the value of 2^(that power) and recheck the values, continuing until there's nothing left. The problem is that I seem to get the same answer (completely incorrect) every time I put a value. Here's the code.

#include <iostream>
#include <math.h>

using namespace std;

int aExp[30] = { 0 };

int Check(int nCount2)
{
    int nExp = 0;
    bool bContinue = true;
    cout << endl <<"in check";
    do
    {
        if(nCount2 > (pow(2,nExp)))
        {
            nExp++;
            bContinue = true;
            cout << endl << "At " << nExp << endl;
        }
        else (bContinue = false);
    }
    while (bContinue);
    aExp[nExp] = 1;
};

int Tally(int nCount)
{
    static int nTally = 0;
    for(int iii = 0; iii < 30; iii++)
    {
        if (aExp[iii] == 1) {nTally = (nTally + pow(2,iii));};
    };
    return nTally;
};


void Count(int nStart)
{
    static int nCount = nStart;
    cout << endl << "in Count";
    while (nCount > 0)
    {
        cout << endl << "before Check"; …
Nick Evan commented: Good first post! +16