I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another
randomly selected one is in 'var2'.
How do I find out the number that is left over?
I tried a while loop but I couldn't get it to work...
TIA 11 1648
fsd,
What I would do is store the values in an ArrayList. When you pick the
numbers randomly, remove them from the ArrayList and place into a new
collection. This would require you to change the range of selected random
numbers every time (the first time you pick a random number from the range
1-3, then 1-2, etc, etc). You just have to stop when you have enough
numbers selected. Then, whatever is left over in the ArrayList is what was
not selected.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"fsd" <sg@hotmial.com > wrote in message
news:bs******** ****@ID-83837.news.uni-berlin.de... I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
I tried a while loop but I couldn't get it to work...
TIA
Something like this (pseudo-code):
var1 = Random(3);
var2 = Random(3);
while (var2 == var1)
{
var2 = Random(3);
}
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"fsd" <sg@hotmial.com > wrote in message
news:bs******** ****@ID-83837.news.uni-berlin.de... I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
I tried a while loop but I couldn't get it to work...
TIA
fsd wrote: I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
I tried a while loop but I couldn't get it to work...
TIA
Add var1 and var2 together
psuedo code;
switch(var1 + var2)
case 3: three is left
case 4: two is left
case 5: one is left
"Sudsy" <bi*********@ho tmail.com> wrote in message
news:3F******** ******@hotmail. com... fsd wrote: I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
I tried a while loop but I couldn't get it to work...
TIA Think! What do the numbers 1, 2 and 3 add up to? Add up the two you know, subtract from 6 and you've got the third.
Simple, but highly effective. Well done.
Seems obvious now, eh?
It does *now*. :)
try this;
int nArrayPos = -1;
for(int x = 0; x < arrayOfVars.Len gth; x++)
{
if(var1 != arrayOfVars[x] & var2 != arrayOfVars[x])
{
nArrayPos = x;
}
}
if(nArrayPos != 01)
MessageBox.Show (arrayOfVars[x].ToString() + " is not beeing used");
"fsd" <sg@hotmial.com > wrote in message
news:bs******** ****@ID-83837.news.uni-berlin.de... I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
I tried a while loop but I couldn't get it to work...
TIA
fsd wrote: I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
if (var1 != var2)
System.out.prin tln ( (6 - var1 - var2) + " is missing" );
else
System.out.prin tln ("Two values are missing, you liar!");
-- Er*********@sun .com
Sorry, the last if should have been;
if(nArrayPos != -1)
"Marco Martin" <ma**********@s ympatico.ca> wrote in message
news:9Y******** ************@ne ws20.bellglobal .com... try this;
int nArrayPos = -1; for(int x = 0; x < arrayOfVars.Len gth; x++) { if(var1 != arrayOfVars[x] & var2 != arrayOfVars[x]) { nArrayPos = x; } } if(nArrayPos != 01) MessageBox.Show (arrayOfVars[x].ToString() + " is not beeing used");
"fsd" <sg@hotmial.com > wrote in message news:bs******** ****@ID-83837.news.uni-berlin.de... I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
I tried a while loop but I couldn't get it to work...
TIA
fsd wrote: I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
Think more mathematically. Sum the numbers you have together, and
deduct them from the sum of all three numbers. No loops required.
Brad BARCLAY
--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org
Unless I'm missing something, this would not work because theoretically you
could get "1" as your answer every time...and that would be stored in each
element of the array list.
Eric
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:#r******** ******@TK2MSFTN GP12.phx.gbl... fsd,
What I would do is store the values in an ArrayList. When you pick
the numbers randomly, remove them from the ArrayList and place into a new collection. This would require you to change the range of selected random numbers every time (the first time you pick a random number from the range 1-3, then 1-2, etc, etc). You just have to stop when you have enough numbers selected. Then, whatever is left over in the ArrayList is what
was not selected.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"fsd" <sg@hotmial.com > wrote in message news:bs******** ****@ID-83837.news.uni-berlin.de... I have three numbers - 1, 2 & 3.
A randomly selected one of the three are stored in 'var1', and another randomly selected one is in 'var2'.
How do I find out the number that is left over?
I tried a while loop but I couldn't get it to work...
TIA
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Martin Marcher |
last post by:
Hi,
I've read several questions and often the answer was
'C knows nothing about .'
So if C knows that little as some people say, what are the benefits, I
mean do other languages know more or is it a benefit that C knows nearly
nothing (what I can think about is that C is the largest common divisor
defined on most available platforms)?
|
by: Perception |
last post by:
Hello all,
If I have a C-like data structure such that
struct Data {
int a; //16-bit value
char; //3 ASCII characters
int b; //32-bit value
int c; //24-bit value
}
|
by: Bit byte |
last post by:
I have the following methods:
static void Foo::setBar(const Bar*) ; //store a copy of Bar
static const Bar* Foo::getBar(void) const ; //return an UNMODIFIABLE ptr
to our internal copy
In another part of my code , I retrieved and used Bar as follows:
....
const Bar* temp = NULL ;
|
by: petermichaux |
last post by:
Hi,
It seems like determining element position in a web page is a difficult
task. In the position reporting source code I've looked at there are
special fixes for at least some versions of Safari and Opera. I am
doing a lot of dragdrop experimentation and in some situations need a
position reporting function. The function doesn't need to report the
positions of exotic elements like images in button elements; however, I
would like a...
|
by: Ethan Furman |
last post by:
len wrote:
I've never had the (mis?)fortune to work with COBOL -- what are the
files like? Fixed format, or something like a dBase III style? I
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |