Math Quiz

Hi, i was following This Math Quiz tutorial for Visual studio.
I hope it’s ok to publish my problem here since unity has C#.
My problem is that all the + , - and x works but my ÷ doesn’t seem to for some reason.

When the Game starts the Division’s stays at 0 so there is no answer.
Any idea why this is happening ?

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 Math_Quiz
{
    public partial class Form1 : Form
    {
        Random randomNumber = new Random();
        int add1;
        int add2;

        int min1;
        int min2;

        int mult1;
        int mult2;

        int div1;
        int div2;


        int timeLeft;

        public Form1()
        {
            InitializeComponent();
        }

        public void startTheQuiz()
        {
            add1 = randomNumber.Next(51);
            add2 = randomNumber.Next(51);
            plusLeftLabel.Text = add1.ToString();
            plusRightLabel.Text = add2.ToString();
            sum.Value = 0;

            min1 = randomNumber.Next(1, 101);
            min2 = randomNumber.Next(1, min1);
            minusLeftLabel.Text = min1.ToString();
            minusRightLabel.Text = min2.ToString();
            minus.Value = 0;

            mult1 = randomNumber.Next(2, 11);
            mult2 = randomNumber.Next(2, 11);
            timesLeftLabel.Text = mult1.ToString();
            timesRightLabel.Text = mult2.ToString();
            product.Value = 0;

            div1 = randomNumber.Next(4, 11);
            int temporaryQuotient = randomNumber.Next(4, 11);
            div1 = div2 * temporaryQuotient;
            dividedLeftLabel.Text = div1.ToString();
            dividedRightLabel.Text = div2.ToString();
            quotient.Value = 0;
        }

        private bool CheckTheAnswer()
        {
            if ((add1 + add2 == sum.Value)
                 (min1 - min2 == minus.Value)
                 (mult1 * mult2 == product.Value)
                 (div1 / div2 == quotient.Value))
                return true;
            else
                return false;
        }

        private void startButton_Click(object sender, EventArgs e)
        {
            startTheQuiz();
            startButton.Enabled = false;

            timeLeft = 30;
            timeLabel.Text = "30 Seconds";
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
         
            if (CheckTheAnswer())
            {
                timer1.Stop();
                MessageBox.Show("You got all the answers right!","Congratulations");
                startButton.Enabled = true;
            }
            else if (timeLeft > 0)
            {
                timeLeft--;

This is propably the wrong place to ask this prblem, if any one knows a active C# forum to please share a link.
Appreciate any help.
~Wentzel

are you using / for divide?

oh and 0 dived by 0 is an incomprehensible number. You can not have nothing of nothing in mathematical terms. In Philosophical maybe, but not math.

Yes for example 6 * 6 = 36
And then i test it by dividing it with /.

i have only been using C# for 2 days so i’m struggling to adjust.

Do you see a problem i missed ?

well your code is quite big. so i am not going thru it. I noticed the line…
(div1 / div2 == quotient.Value))

if that is how you are dividing, as long as div2 has a value != to 0, you should be ok.

the problem is this line: div1 = div2 * temporaryQuotient;
that should be div2 = div1 * temporaryQuotient;

At the moment you are multiplying 0(div2) with the quotient which results in 0.

@Zerot : I feel Stupid :smile:
Thanks for the solution.

Please do not post general non-Unity programming questions here. There are many programming forums you can visit, this one is for Unity only.

–Eric