Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8108681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:11:22+00:00 2026-06-06T01:11:22+00:00

Please have a look at the following code namespace Funny { class QuesionsAndAnswers {

  • 0

Please have a look at the following code

namespace Funny
{
    class QuesionsAndAnswers
    {
        private double firstNumber;
        private double secondNumber;
        private double userAnswer;
        private double computerAnswer;

        private string operators;

        private bool answerCorrect;
        private bool enableDouble;

        private double[] listOfNumbers;
        private string[] listOfOperators;

        private Random randomizer;

        private static QuesionsAndAnswers qa;

        private QuesionsAndAnswers()
        {
            randomizer = new Random();

            listOfNumbers = new double[] { 1,2,3,4,5,6,7,8,9 };
            listOfOperators = new string[] { "+", "-", "*", "/" };
        }

        public static QuesionsAndAnswers getQuesionsandAnswersInstance()
        {
            if (qa == null)
                qa = new QuesionsAndAnswers();
             return qa;
        }

        public string generateQuestions()
        {
            string result = "";

            operators = listOfOperators[randomizer.Next(listOfOperators.Length)];
            firstNumber = listOfNumbers[randomizer.Next(listOfNumbers.Length)];
            secondNumber = listOfNumbers[randomizer.Next(listOfNumbers.Length)];

            if ((operators.Equals("/")) && (enableDouble == false))
            {
                while (firstNumber % secondNumber == 0)
                {
                    firstNumber = listOfNumbers[randomizer.Next(listOfNumbers.Length)];
                }
                result = firstNumber + operators + secondNumber;
            }
            else if (operators.Equals("-") && (firstNumber<secondNumber))
            {
                while (firstNumber > secondNumber)
                {
                    firstNumber = listOfNumbers[randomizer.Next(listOfNumbers.Length)];
                    secondNumber = listOfNumbers[randomizer.Next(listOfNumbers.Length)];
                }
                result = firstNumber + operators + secondNumber;
            }
            return result;
        }

        public void setDoubleAnswers(bool check)
        {
            enableDouble = check;
        }
    }
}

In here, in the generateQuestions() method, I am trying to generate some math questions.

If operator in “-” and if the firstNumber < secondNumber, then should re generate numbers (first number and second number) to make sure the answer is not a minus value.

And, if the operator is “/” and the boolean value is false, it should regenerate numbers again to make sure the the answer (which means the calculation, for an example 2/1 = 2) doesn’t contain any floating points (which means it should not generate questions like 2/3, because the answer contains floating points).

In my attempt, both above are not happening. It still generates unexpected answers or, sometimes nothing. Why is that? Please help

Please note, I am a Java developer and this is my first major C# project.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:11:24+00:00Added an answer on June 6, 2026 at 1:11 am

    Well, it returns nothing sometimes because, other than the edge cases you’re catching, you never set result to anything other than "".

    And both your while statements are the wrong way around. It should be:

    while ((firstNumber % secondNumber) != 0)
    :
    while (firstNumber < secondNumber)
    

    However, for efficiency, I wouldn’t do that second while since you may get a long run of pairs where that property holds. If the numbers are the wrong way around, just swap them.

    And there’s precious few cases where the remainder will be zero from your number selection (9/3, 8/4, 8/2, 6/3, 6/2, 4/2, M/M and N/1 is (I think) the exhaustive list). If you want a more expanded set of equations, I would go the other way and choose two numbers to mutiply, then swap the first with the result.

    For example, given the two numbers a = 3 and b = 7, simply do:

    a = a * b;
    

    and you have a = 21, b = 7 which is guaranteed to give an integral multiplier and deliver the equation "21 / 7".


    So this (psuedo-code) is what I would start with:

    # Get the random values.
    
    op = random_from ("+-/*")
    n1 = random_from ("123456789")
    n2 = random_from ("123456789")
    
    # For subtraction, make sure n1 >= n2.
    
    if op = "-" and n1 < n2:
        tmp = n1;
        n1 = n2;
        n2 = tmp;
    
    # For division, make sure n1 is integral multiplier of n2.
    
    if op = "/":
        n1 = n1 * n2
    
    # Return expression in ALL cases.
    
    return n1 + op + n2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
am new here. i have a slight problem; PLease look at the following code
Please have a look at the following code, which I have run in VB6
Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout;
Please have a look at the following code. import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.*;
Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue;
Please have a look at the following code import java.awt.event.*; import javax.swing.*; import java.awt.*;
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
Please have a look at the following code: #include <stdio.h> #include <stdlib.h> typedef struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.