Click here to Skip to main content
15,881,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCRichEditCtrl FindText problem Pin
ForNow5-May-12 20:24
ForNow5-May-12 20:24 
AnswerRe: CRichEditCtrl FindText problem Pin
enhzflep5-May-12 21:44
enhzflep5-May-12 21:44 
GeneralRe: CRichEditCtrl FindText problem Pin
ForNow6-May-12 5:41
ForNow6-May-12 5:41 
GeneralRe: CRichEditCtrl FindText problem Pin
enhzflep6-May-12 5:54
enhzflep6-May-12 5:54 
QuestionLooping when you need user input Pin
abollmeyer5-May-12 19:25
abollmeyer5-May-12 19:25 
AnswerRe: Looping when you need user input Pin
Code-o-mat5-May-12 23:08
Code-o-mat5-May-12 23:08 
GeneralRe: Looping when you need user input Pin
abollmeyer6-May-12 3:37
abollmeyer6-May-12 3:37 
GeneralRe: Looping when you need user input Pin
enhzflep6-May-12 4:15
enhzflep6-May-12 4:15 
Not really able to acertain your level of programming experience, though it does sound like perhaps you're coming from a background in DOS or console app programming - not the event driven model that's used in windows.

I say that in reference to your mention of loops.

For this kind of a question, a loop in the classic sense is not appropriate. Think of your code as a state-machine. Every time something happens on the form, windows calls the appropriate function in your code and you handle it. Rather than looping, you should increment a counter that indicates the current question. If you then use this counter in all of your functions that display num1 & num2, or check for the correct answer you're done.

Here's something I just had a play with. It should be enough to demonstrate the ideas you need.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace mathProj
{
    public partial class Form1 : Form
    {
        private const int maxQuestions = 50;
        private int curQuestion;
        private int[] num1 = new int[maxQuestions];
        private int[] num2 = new int[maxQuestions];

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool isCorrect;
            textBox1.Text = curQuestion.ToString();
            if (curQuestion < maxQuestions-1)
                curQuestion++;
            else
            {
                initNumbers();
                curQuestion = 0;
            }
            setNumberLabels();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            initNumbers();
            setNumberLabels();
        }

        private void setNumberLabels()
        {
            lblNum1.Text = num1[curQuestion].ToString();
            lblNum2.Text = num2[curQuestion].ToString();
        }

        private void initNumbers()
        {
            curQuestion = 0;
            int i;
            for (i = 0; i < maxQuestions; i++)
            {
                num1[i] = i*2;
                num2[i] = i*3;
            }
        }
    }
}

GeneralRe: Looping when you need user input Pin
abollmeyer6-May-12 7:32
abollmeyer6-May-12 7:32 
GeneralRe: Looping when you need user input Pin
enhzflep6-May-12 7:40
enhzflep6-May-12 7:40 
GeneralRe: Looping when you need user input Pin
Code-o-mat7-May-12 4:03
Code-o-mat7-May-12 4:03 
GeneralWelcome Pin
Code-o-mat5-May-12 23:11
Code-o-mat5-May-12 23:11 
Question64 bit problem Pin
appollosputnik4-May-12 4:41
appollosputnik4-May-12 4:41 
AnswerRe: 64 bit problem Pin
Albert Holguin4-May-12 9:58
professionalAlbert Holguin4-May-12 9:58 
AnswerRe: 64 bit problem Pin
«_Superman_»4-May-12 16:43
professional«_Superman_»4-May-12 16:43 
QuestionHelp for algorithm Pin
Falconapollo3-May-12 23:53
Falconapollo3-May-12 23:53 
QuestionRe: Help for algorithm Pin
Maximilien4-May-12 2:38
Maximilien4-May-12 2:38 
AnswerRe: Help for algorithm Pin
«_Superman_»4-May-12 3:15
professional«_Superman_»4-May-12 3:15 
GeneralRe: Help for algorithm Pin
Falconapollo5-May-12 20:12
Falconapollo5-May-12 20:12 
AnswerRe: Help for algorithm Pin
Albert Holguin4-May-12 10:12
professionalAlbert Holguin4-May-12 10:12 
GeneralRe: Help for algorithm Pin
Falconapollo5-May-12 20:29
Falconapollo5-May-12 20:29 
QuestionRe: Help for algorithm Pin
CPallini4-May-12 10:47
mveCPallini4-May-12 10:47 
AnswerRe: Help for algorithm Pin
Falconapollo5-May-12 20:37
Falconapollo5-May-12 20:37 
QuestionRe: Help for algorithm Pin
CPallini6-May-12 22:42
mveCPallini6-May-12 22:42 
AnswerRe: Help for algorithm Pin
Falconapollo8-May-12 19:30
Falconapollo8-May-12 19:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.