Hi, is there anyone who can help me with a division problem i;m having
I an using VB6. I am writing a program wich asks the user to give the correct answer to a given sum, it should give two number which can be easily divided
by a 8 year old and it should be a answer without the comma part
for instance it should give a sum like 10 / 2 and not 19 / 3.
Is there some type of test that i can let it run before it asks the question to make sure that the greater number is diviseable by the smaller number to give an non comma answer eg: 3,4567 or something the like, it should preferably just be a 1 digit answer.
my code looks like this
Dim a, b ,c as Long
a = 1 + Int(Rnd * 12)
b = 1 + Int(Rnd * 12)
c = a / b
Label2.Caption = a
Label3.Caption = b
Label4.Caption = c
which work fine but not good for an 8 year old, please help if you can
Thanks
13 2104
try this
Dim a, b ,c as integer
a = Int(Rnd * 12)+1
b = Int(Rnd * 12)+ 1
c = a / b
if a > b then
c = b / a
else
c = a / b
end if
Label2.Caption = a
Label3.Caption = b
Label4.Caption = c
tell me if it work im just guessing
:)
ok what happens is this, it gives a sum for example
9 ÷ 7 = 1 which is true because 7 does go into 9 once but there is a remainder 2
which it doesent show, thats using the / operator, the object is to get two
numbers that can be divided with an answer that is comprehendable by an eight
year old, something like 10 ÷ 2 or 8÷4, that where the problem lies, getting
number to divide without remainders
Thanks for your reply it is greatly appreciated
Regards
Sunray
Given two numbers, you should be able to check whether the result is a whole number by something like this... - Public Function DivisibleBy(byval Num1 As Long, byval Num2 As Long) As Boolean
-
DivisibleBy = ( Num1 \ Num2 ) = ( Num1 / Num2 )
-
End Function
I haven't tested this - it may require a little intermediate work to ensure that decimals aren't truncated/rounded to fit the Long data type.
As for checking whether it's a "non commas" answer, I think what you're really asking is, is it > 999? It shouldn't be too hard to work out the answer. :)
Killer i tried your method and a whole slew of others but it seems to me that no one can get it right out there, i tried the prime numbers effect try make the program miss the prime numbers but my efforts fell flat on its face then
Is there a method that u can use to make the program only see numbers that can be divided equally into themselves without the need for kilometers of code
can u make it see only certain prime numbers and is there an easy way to get rid of the comma, answers with a comma? the answer nust just be a whole number, damn my head is flat now, anything you guys can help me with that will help me will be appreciated even if you just give me a smell that i can follow
i downloaded about a hundred divisor and interger and prime number sample code sources, but alas could get no wiser
I am still using Microsoft Visual Basic 6.0 and and the mdsn site didnt offer much help iether
Don't torture yourself generating two random numbers and trying to figure out if they are divisible. Instead, predetermine the largest number you want to use as a denominator and generate a random integer within that limit. Then generate an integer multiplier between 1 and 9 (you wanted the answers to be a single digit) and multiply the denominator by that result to give you the numerator. The following code will give you problems with a maximum denominator of 15 and all answers are single digits but you can change that by initializing limitDenom and limitAnswer to different values (I haven't tested the code): - dim denom, multiplier, limitDenom, limitAnswer as Integer
-
-
'--Initialize limits to division problem arguments.
-
limitDenom = 15
-
limitAnswer = 9
-
-
'--Establish the demoninator for the problem.
-
denom = CInt(Int((limitDenom * Rnd()) + 1))
-
-
'--Establish a multiplier between 1 and limitAnswer.
-
multiplier = CInt(Int((limitAnswer * Rnd()) + 1))
-
-
'--The numerator is the product (denom * multiplier) and multiplier is the dividend.
-
Label2.Caption = (denom * multiplier)
-
Label3.Caption = denom
-
Label4.Caption = multiplier
Good Luck,
Michael Bailey
Haven't had time to fully read the last two messages, but here's a modified version of the "are these divisible?" function. This time, I've tested it, and it works. - Public Function DivisibleBy(ByVal Num1 As Long, ByVal Num2 As Long) As Boolean
-
Dim Sng1 As Single, Sng2 As Single
-
Sng1 = Num1: Sng2 = Num2
-
DivisibleBy = ((Sng1 \ Sng2) = (Sng1 / Sng2))
-
End Function
(I will get through the rest of the thread in a few hours.)
Haven't had time to fully read the last two messages, but here's a modified version of the "are these divisible?" function. This time, I've tested it, and it works. - Public Function DivisibleBy(ByVal Num1 As Long, ByVal Num2 As Long) As Boolean
-
Dim Sng1 As Single, Sng2 As Single
-
Sng1 = Num1: Sng2 = Num2
-
DivisibleBy = ((Sng1 \ Sng2) = (Sng1 / Sng2))
-
End Function
(I will get through the rest of the thread in a few hours.)
There is no need to though. If you understand the data type. Long Integer variables (declare as Long) can store Integer (not comma number) only. When you divide two integer number, the result will be a Real Number. In VB, Real number are known as Single and Double.
Use Single (or double) variable to store result from dividing, so you will get the number with comma. If you used Long variable to store result, you will get the non-comma variable. That's simple
Thanks a million you guys, it is really appreciated, i will get to work on it now again.
This is a fantastic site
Best Regards
hahahahahahahahahaha
i wish you guys could see me laughing now
it worksm it works, it works
it works like a charm
exactely what i was looking for
again cant tell you guys how much i appreciate it
There is no need to though. If you understand the data type. ... That's simple
Actually, it's not always that simple.
I may be getting VB mixed up a bit with Natural (a programming language I use on the mainframe). But I believe that in calculations it tends to convert everything to the smallest data type that it thinks may be necessary (and doesn't always make a good choice). So if you mix up different data types such as Long and Single in a statement, you can receive unexpected results.
I guess your best bet is to "suck it and see" as the saying goes. If it works, fine. If not, convert everything first. What I did with that Function was to write it in a generic manner that I could be pretty certain would always work.
... Use Single (or double) variable to store result from dividing, so you will get the number with comma. If you used Long variable to store result, you will get the non-comma variable.
This reveals a bit of a "cultural divide" stemming from the fact that we have members residing all over the world.
In Australia, the U.S., Britain and I don't know where else, a comma is the "thousands delimiter", while a dot is the decimal separator. Which means that in those countries, what you said is complete nonsense. Regardless of data type, any number greater than 999 can be considerd a "comma number" (not that I've ever heard this expression outside of TheScripts).
In many other parts of the world, and this obviously includes you, pureenhanoi) it works the other way around. The comma is used as the decimal separator, while the dot separates the groups of digits in large numbers. So the expression "comma number" would presumably refer to a non-integer amount.
Neither way is "right" or "wrong", except within the context of a particular country. For example, if you take ten million and one, and divide it by two, the answer will be the same anywhere, but might look different, depending on who displayed it. - Killer42 (Australia):
5,000,000.5 - pureenhanoi (?):
5.000.000,5
it works like a charm
exactely what i was looking for
You don't actually say what it was that solved the problem. But I'm certainly glad we could help. :)
This reveals a bit of a "cultural divide" stemming from the fact that we have members residing all over the world.
In Australia, the U.S., Britain and I don't know where else, a comma is the "thousands delimiter", while a dot is the decimal separator. Which means that in those countries, what you said is complete nonsense. Regardless of data type, any number greater than 999 can be considerd a "comma number" (not that I've ever heard this expression outside of TheScripts).
In many other parts of the world, and this obviously includes you, pureenhanoi) it works the other way around. The comma is used as the decimal separator, while the dot separates the groups of digits in large numbers. So the expression "comma number" would presumably refer to a non-integer amount.
Neither way is "right" or "wrong", except within the context of a particular country. For example, if you take ten million and one, and divide it by two, the answer will be the same anywhere, but might look different, depending on who displayed it.- Killer42 (Australia):
5,000,000.5 - pureenhanoi (?):
5.000.000,5
May be you are right. But comma was often used in my country to seperate decimal (dot was used to seperate thousand). We always use comma for writting on books, on papper but not often use on compute soft-ware. I'm sorry if some one cant understand this different.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: joel |
last post by:
I have a table which I want to update by dividing one field into
another. The update runs with no errors, but the results come out as
only a positive integer number.
The datatype for the result...
|
by: Marcin |
last post by:
How I can make division of two numbers placed in arrays, example:
short int a = {2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2};
short int b =...
|
by: Daisy |
last post by:
Something simple, I'm sure. My code:
System.Windows.Forms.MessageBox.Show(((Int32)Math.Ceiling(1966 /
100)).ToString());
I'm expecting 20, but getting 19. What am I doing wrong?
Thanks
--
|
by: seb.haase |
last post by:
Hi,
Is it true that that "Python 3000" is dead ?
Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would
just break to much code :-(
On the otherhand I'm using Python as "Matlab...
|
by: Mike S |
last post by:
Does anyone know the logic behind why in VB.NET the result of a
floating-point division ('/') is -rounded- on being converted to an
integer type, such as with statements like
Dim x As Integer =...
| |
by: Jon Vaughan |
last post by:
Can someone tell me why the following statement gives me the result of 0 :
Math.Ceiling( 1 / 12);
Well actually the above is simplefied from :
private const int LocationsPerPage = 12;
...
|
by: kermit |
last post by:
For a long time,, There has been a discussion of trueFor division
versus integer division in Python.
I myslef prefer that / be used for integer division since almost
always, I want the...
|
by: jamesonang |
last post by:
Supposed unsigned int(32 bits) is the largest number that computer can
represent with a single variable.
Now, i have a big integer ( less than 64 bit, but great than 32 bit) .
i represent it by...
|
by: Rory Campbell-Lange |
last post by:
>>(1.0/10.0) + (2.0/10.0) + (3.0/10.0)
0.60000000000000009
0.59999999999999998
Is using the decimal module the best way around this? (I'm expecting the first
sum to match the second). It seem...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |