To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 27266
27265  |  27267
Subject: 
Re: Prime number generator
Newsgroups: 
lugnet.robotics
Date: 
Mon, 15 Oct 2007 16:00:52 GMT
Viewed: 
5103 times
  
In lugnet.robotics, linmix <linmix@gmail.com> wrote:
Can anyone explain why this doesn't work as expected and maybe even
provide a workaround?

SetUserDisplay hooks up the display to whatever source you specify and until you
tell it to hook up to a different source it will continue to display the value
of that source until the program ends. The first time that your NQC code enters
the div == nmb/2 if statement you have hooked up the LCD to the nmb variable and
as that variable's value changes it will show each value. If you do not want to
continually show nmb's value then you need to use SetUserDisplay or
SelectDisplay to tell the LCD to display something other than nmb's value.

The behavior of SetUserDisplay is fairly well documented in the NQC Programmer's
Guide (which is duplicated in the BricxCC help system).


"Set the LCD display to continuously monitor the specified value. Precision
specifies the number of digits to the right of the decimal point. A precision of
zero shows no decimal point."

There are a number of ways you could change your program to work correctly.  You
could hook the display to a global variable that only ever contains prime
numbers or zeros. In your div = nmb/2 if statement you could set this variable
to nmb or zero depending on the conditional value.

Alternatively, you could call SetUserDisplay in the if clause and add an else
clause that hooks the display to something else so that only when the comparison
is true will the display be hooked up to the nmb variable.

John Hansen



Message is in Reply To:
  Prime number generator
 
I've been trying to write a prime number generator in NQC by way of exercise to improve my programming skills, but I've run into some unexpected trouble. I have two sets of code that are virtually identical, one in NQC and the other in plain C. The (...) (17 years ago, 13-Oct-07, to lugnet.robotics)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR