Re: NXT PROBLEM
Posted: 20 Jun 2013, 21:16
				
				You should have told me this from the start. I gave you the code, You didn't even look at it...
			Give a child a robot, he'll play for an hour. Teach him to build, and he'll play forever.
https://mindboards.org:443/
Code: Select all
task main() {
ClearScreen();
int y;
int i;
int MyArray[100];
            SetSensorLowspeed(IN_4);
                  for (i=0;i<=100;i++) {
                  y= SensorUS(IN_4);
                  MyArray[i]=y
                  NumOut(0, 56, y, DRAW_OPT_CLEAR);
                   }
                  for (i=0;i<=100;++i) {
                  y=MyArray[i];
                  if (i==99) ClearScreen();
                  PointOut(i, y/4, DRAW_OPT_NORMAL);
                  }
          while (true);
}Code: Select all
int main(int argc, char *argv[])
{
    ...
    while (x == y) {
        something();
        somethingelse();
 
        if (some_error) {
            /* the curly braces around this code block could be omitted */
            do_correct();
        } else
            continue_as_usual();
    }
 
    finalthing();
    ...
}
have a look at this link: http://en.wikipedia.org/wiki/Indent_style#K.26R_styleThe K&R style, so named because it was used in Kernighan and Ritchie's book The C Programming Language, is commonly used in C. It is also used for C++, C#, and other curly brace programming languages.
Code: Select all
task main()
{
    ClearScreen(); 
    int y;   
    int i;    
    SetSensorLowspeed(IN_4); 
   
    for (i=0;i<=100;++i)     
    {
        if (i>=100) {i=0; ClearScreen(); }    
        y = SensorUS(IN_4);    
        LineOut(i, y/4, DRAW_OPT_NORMAL);    
        NumOut(0,56, y, DRAW_OPT_CLEAR);    
    }
    while (true);    
}Code: Select all
lines 1-4 in the main body: initialize.
 
for loop: 
- you poll a sensor value and assign it to y.
- you make a line out every time for each i
- you make a num out for every i
when the for loop is done once, then the program terminates in a perpetual wait state (while(true) ).