Distinguishing the lowest test score in a while loop

Hi,
I am working on a program that collects a series of test scores from the user. The program should tabulate the scores and it should highlight the lowest score amongst the other test scores, but there within lies the problem for me. This is what my program looks like at this moment:
import java.util.*;
public class ArrayOfTestScores
    public static void main(String[] args)
        int[] testScore = new int[5];
        int count, max, min, next, number;
        int sum, average, lowScore, bottomScore;
        Scanner keyboard  = new Scanner(System.in);
        lowestScore = 0;
        sum = 0;
        System.out.print("Enter score for test 1: ");
        max = keyboard.nextInt();
        number = 1;
        count = 1;
        while(count<5)
            System.out.print("Enter score for test" + (number+1) +": ");
            testScore[count] = keyboard.nextInt();
            testScore[0] = max;
            min = max;
            next = testScore[count];
            if(next > max)
                max = next;
            else
                min = next;
                if(next < min)
                    min = next;
                else
                    max = next;
            sum = sum + testScore[count];
            min=lowestScore;
            number++;
            count++;
        bottomScore = lowScore;
        for(count = 0; count < testScore.length; count++)
            if(testScore[count]==bottom)
                System.out.println("Test" + (count+1)+ testScore[count]+ "lowest score");
            else
                System.out.println("Test" + (count+1)+ testScore[count]);
}Here is a sample of what the output looks like:
Enter score for test 1: 50
Enter score for test 2: 70
Enter score for test 3: 22
Enter score for test 4: 90
Enter score for test 5: 99
Test 1: 50
Test 2: 70
Test 3: 22 lowest score
Test 4: 90
Test 5: 99
If there is anyone out there who can assist me with this program, I would appreciate it tremendously.

Here's part of your codeelse
                min = next;
                if(next < min)
                    min = next;
                else
                    max = next;
            }So, first min is set to the same value as next. Then you have an if statement that tests to see if next is less than min. How can that ever happen if min=next?

Similar Messages

  • How to make the exchange of data between 2 while loop in real time

    hello
    I have 2 while loop
    the 1st while loop includes the data acquisition program
    the 2nd while loop includes the control program
    my question is how to make the exchange of data between 2 while loop in real time
    I tried with the local variable and direct wiring between the 2 while loop
    it does not work (there is a delay)
    Solved!
    Go to Solution.

    Bilalus,
    Queues are only good to transfer data if your application isn't deterministic. Since you are using Real Time, I am assuming that your application requires determinism. If you are using Timed Loops and you use queues to transfer data between your loops, you are losing determinism. In this case, you need to use the RT FIFO functions. 
    Warm Regards,
    William Fernandez
    Applications Engineering
    National Instruments

  • Why the execution time increases with a while loop, but not with "Run continuously" ?

    Hi all,
    I have a serious time problem that I don't know how to solve because I don't know exactly where it comes from.
    I command two RF switches via a DAQ card (NI USB-6008). Only one position at the same time can be selected on each switch. Basically, the VI created for this functionnality (by a co-worker) resets all the DAQ outputs, and then activates the desired ones. It has three inputs, two simp0le string controls, and an array of cluster, which contains the list of all the outputs and some informations to know what is connected (specific to my application).
    I use this VI in a complex application, and I get some problems with the execution time, which increased each time I callled the VI, so I made a test VI (TimeTesting.vi) to figure out where the problem came from. In this special VI I record the execution time in a csv file to analyse then with excel.
    After several tests, I found that if I run this test VI with the while loop, the execution time increases at each cycle, but if I remove the while loop and use the "Run continuously" funtionnality, the execution time remains the same. In my top level application I have while loops and events, and so the execution time increases too.
    Could someone explain me why the execution time increases, and how can I avoid that? I attached my test VI and the necessary subVIs, as well as a picture of a graph which shows the execution time with a while loop and with the "run continuously".
    Thanks a lot for your help!
    Solved!
    Go to Solution.
    Attachments:
    TimeTesting.zip ‏70 KB
    Graph.PNG ‏20 KB

    jul7290 wrote:
    Thank you very much for your help! I added the "Clear task" vi and now it works properly.
    If you are still using the RUn Continuously you should stop. That is meant strictly for debugging. In fact, I can't even tell you the last time I ever used it. If you want your code to repeat you should use loops and control the behavior of the code.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How do you plot multiple curves on the same graph when using a while loop?

    I am writing a program that will plot the IV Output chracterisitcs curves for a MOSFET transistor. I have two sweep variables Vg and Vd. For each Vg valve selected, Vd is swept from its start to stop voltage creating a graph for that Vg valve. Both of the sweeps are done using while loops. Ideally I would like to display all of the Vg plots on the same graph while having the ability to do real-time graphing. Can anyone help me figure this problem out? I have attached my program. Thanks!!
    Tammy
    Attachments:
    outputfin2.vi ‏165 KB

    Hi Tammy & Tica T,
    As far as I see it - this thread is a very bad version of already existing bad version......
    http://forums.ni.com/ni/board/message?board.id=170&message.id=127857
    I expected, that an Applications Engineer from NI knows something about  a Transistor and how an Output characteristic looks like !!  Take a look to a typical Transistor Datasheet ( e.g. n-channel MOSFET) - you will see, that there is no relation of ID vs Time like in your example ( values vs time )  but  IDrain vs VDrain at different VGate's ( no relation to Mr. Bill Gates ).
    Find attached a vi, that in general does what you need - drawing of  curves vs x-axis (XY-graph in use)  - in test_sweep.zip.  And that you geet an impression, how it might be done ...... dynamic Output characteristic of a Transistor with Standard Equipment of a Lab ( Scope + Generator + Power Supply ) find in addition a Frontpanel - picture. One of the interesting points here is - the self-heating effect; visible on ch3 of scope - 5µs Pulse is already a very long time...... This measurement was done in order to compare with our own Transistors......... 
    Hope this helps a little bit to understand, what we are talking about.
    Regards
    Werner
    Attachments:
    test_sweep.zip ‏358 KB
    dynamic Transistor char.png ‏65 KB

  • Use the LabView time delay in a while loop instead of using the instrument inherent time loop.

    I have a zes lmg500 that I use. It has the option of continues measuring data, with a user control cycle loop (still using a while loop but the delay is coming from the instrument). The problem is that the loop time is not constant. Can I use a very short time (100ms) as the instrument cycle time but use a longer time delay in the while loop that collect the data?
    I know many instrument offer the same abilities, so the question is relevant to all of them.
    Thanks for any help
    Solved!
    Go to Solution.

    Does that measurement VI have built-in wait functionality and a timeout?
    If not, then you are simply polling the VI at 1 kHz, but I suspect that this is not the case or your Waveform Chart probably wouldn't look as you expect (getting 0's put in everytime measurement data is not available).
    I expect that if you have the instrument set up to send data at a fixed time interval (i.e. 100 ms), all the data that it is sending you will end up residing in your serial buffer (or the instrument driver will have taken it out and put it in another internal buffer), so if you come back to read it 1 sec later, then you will have 10 data points to go through.  Whether you can read them all at once with the read VI or have to call it a whole bunch of times until empty I can't say.
    What is your objective?

  • Way to Capture Pre-Test Score?

    Hi all -
    We're using OLM 11.5.10j and want to have a pre-test that, if passed, exempts you from needing to complete the course with which it's associated, and would also mark the overall course as complete. If the learner doesn't pass the pre-test, they would have to take the course + post-test. We also want to capture the pre-test and post-test score separately, so that we know what the score on the pre-test was and, if applicable, the score on the post-test.
    We thought about using two separate "courses" - pre-test, and course+post-test - as part of a Learning Path. That way, we could set the Learning Path to have "at least one component mandatory" and set a the pre-test as a mandatory pre-req on the course+post-test. However, that's a little clunky and really isn't a Learning Path.
    We've looked into other AICC-spec fields that are available in OLM to which the learning object would post additional values to show pre-test/post-test score, then report on those spare fields to determine the respective scores. However, we ran into issues understanding what fields were available in OLM for the LO to post to.
    Any suggestions on how to implement this? Thanks!

    Hello Lee
    You can use DFF attributes in OTA_DELEGATE_BOOKINGS table to store Pre-Test Score and Post-Test Score. Build a class just like any other class......
    Class has 3 Main sections
    1. Pre-Test Section
    2. Class
    3. Test
    If the employee passes the Pre-Test Section...Employee can either continue to take the class or else give the credit to employee for the entire class. (Storing the Pre-test Score in one of the attribute is similar to the way we change the date_status_changed field in OTA_DELEGATE_BOOKINGS table.)
    If employee doesnt clear the pre-test section then save the pre-test-score using package/plsql api to store in DFF attributes of OTA_DELEGATE_BOOKINGS table and continue...rest is the normal process as in other anyother class....
    Hope this helps.....
    I am also expecting some one to give a nice solution.
    Thanks,
    Srujan

  • How to stop execution in while loop without stopping execution of other loops in the same vi

    HI
    I am quite a novice in Labview.
    I have a problem in my project. I used a while loop inside my vi to build an array of ten values along with other loops. Then I used a stop button to stop manually the while loop. But it seems like the loop doesn't stop in the middle of the array building and so other loops in the vi doesn't work until the while loop finishes building the array and as soon as while loop execution is over, the complete vi stops. But all that I wanted was to build the array using the shift register along with the control to stop building array anytime. And not to stop execution of other structures when the while loop finishes.
    Can anyone help me?
    Rahul

    Hi Rahul,
    Modified ur Vi to work with single button.
    But the subtract case is not in any loop.
    So, once both the loops stop, the subtract case will execute only once. Depending on state of subtaract boolean at that time, corresponding case will be executed and the Vi will stop.
    so think of a logic where u can put this also in a new loop.
    Or you can also incorporate it in one of the two loops and pass the other loop's data to it.
    Let us know how you will proceed in this regard
    I am posting your VI as well a VI with my modifications VI in Labview 7.0 so that Thomas can give his suggestions too
    Plus, always keep a time delay in your while loops.
    Oh sorry, the "arrayinouttestnewfinal.vi" is the modified vi
    Regards
    Dev
    Message Edited by devchander on 01-10-2006 06:15 AM
    Message Edited by devchander on 01-10-2006 06:19 AM
    Attachments:
    arrayinouttestnewfinalnew4.vi ‏59 KB
    arrayinouttestnewfinal.vi ‏63 KB

  • Using the Wait function in while loops?

    Hi,
    I have a rather complicated top level VI with about 20 subVIs and the main VI has on big while loop around it and another smaller one inside, basically it runs rather slow and I have no idea how to set the wait function. I mean what factors should I consider..what would be the difference between setting it to 10 and 100 (besides the obvious 10ms vs 100ms)? I just want to increase the performance of the executable, so it is not that slow. Can you offer some hints as to what I need to take into consideration when determining my delay? And also, are while loops the only place that I should use the delay or are there other instances too?

    Adding waits is not a fix-all for slow running applications. Its just one thing that can be done to improve things. If you determine that a sub-vi is causing your problems then you need to find out exactly what that vi is doing to slow you down. If its because there is a loop inside it that is running constantly as fast as it can, then a delay in that loop may help. If that is not your problem then you need to look at other ways to boost performance. It sounds like you have alot of locals variables, each instance of a local variable makes a copy of the data that's in the control. If the controls/indicators that you have local variables of contain large amounts of data then you may be filling up memor
    y with copies of it.
    I suggest that you study the "Performance and Memory Management" chapter of the LabVIEW manual. This can found in the printed manual of the older versions, in the online manuals that install with 6i, or on NI's web site here: http://zone.ni.com/devzone/conceptd.nsf/2d17d611efb58b22862567a9006ffe76/732cec772aa4fbe586256a37005541d3?OpenDocument , which is Application Note 168. This should give you some good ideas of what to look for to improve your performance.
    Hope this helps.
    Brian

  • While loop never stops after reading the result

    I 'amattaching the program with thismessage in which while loop never stops, going on continuing until I stops it manualy using the off button What i have to do to get it off automatically afetr execution and reading the query and getting the result in Read in Front panel
    Attachments:
    PMd VI.vi ‏33 KB

    Your stop condition is "continue if true". This means that, unless you press the button, the while loop will stop after one iteration.
    First, you should change the termination condition to "stop if true".
    Then you should make the stop button "latch when released" (right-click..mechanical action). Else you don't have a well defined state after the program stops.
    You should decide on a reasonable loop rate and enter it for the wait control. (beter use a diagram constant if the value is always the same).
    Why do you need to continue reading in a loop? Are you expecting the response to change over time?
    Do you want to keep appending to the string indicator or only show the latest characters received?
    Maybe you also need a wait between the writing and reading?
    Delete the ms timer value indicator, it is completely useless.
    Do you get any error codes?
    Don't use the run continous button. Use the plain run button.
    What device are you communicating with? Do you have documentation?
    LabVIEW Champion . Do more with less code and in less time .

  • While Loop - Iteration Terminal

    Why the iteration terminal in my upper while loop counts only to 1? (err_while.vi)
    Petr Bilovsky
    Attachments:
    err_while.rar ‏289 KB

    Hi PetrB
    I tested your vi. Results are unexpected.
    Upper loop runs to 10 and stops.Down loop keeps running and it should not, because the inputs to AND gate are TRUE.
    I deleted down loop and copied upper loop ant Now they stop at 10.
    I don´t know your DLL, so try to make it reentrant to avoid side efects.
    Hope this helps.
    Alipio
    "Qod natura non dat, Salmantica non praestat"

  • How can I opearate indicator outside while loop?

    I do small program, I have many while loops and I want to connect wire (in my application) from each loop to AND gate then to another while loop, but how can I operate these wires to agree with the change of my application inside while loops.
    If not clear :
    In another words, suppose I want to operate indicator ouside the while loop. How can I operate indicator outside while loop, so when my application become TRUE (inside while loop) the indicator will be ON (outside while loop) and when my application become FALSE(inside while loop) the indicator will be OFF (outside while loop).
    Help me if you have any idea please..........................

    Hi Rammo,
    For the wire to carry the boolean condition from the while loop to an 'and' gate outside, the while loop must stop running
    If you want the while loop to keep on running and still pass a boolean value to a destination outside the while loop, use any one of these: property nodes, global or local variables.
    i am still not clear as to what you intend to say by this sentence
    " I want the wire that comes out from the while loop will become TRUE if it in my application is TRUE inside while loop and the opposite is true. Because I want to connect the wire that comes out from while loop to AND gate than to another application"
    plz tell me if the first part of this mail of mine answers your doubt or do you need more information?
    regards
    Dev

  • How can I make a while loop wait for input boolean?

    Hi.
    I'm trying to control a robotic arm with labview for my undergrad dissertation, and I have a decent polar coordinate control panel made, but there is one problem; it checks for changes in the coordinates every five seconds, while I want it to only check on the touch of a button (ie, go!, I've changed your coordinates!). The changes are calculated with a while loop comparing the last value of theta, x and z in a while loop with the current one. I can't find a way of putting that into a case structure. If there is a way of making the while loop progress at the push of a button, I think it would work. The VI's attached below.
    Thanks in advance for any help.
    Cathal Scanlon
    ps, sorry about the mess, I'm going to reorganise the while loop into 2 if I can get the control button working.
    Message Edited by CatScan on 02-08-2007 02:45 PM
    Attachments:
    Polar coord assignment1.vi ‏142 KB

    Have you tried using an event structure? To use one, right click on the structure to add an event. Set the event as whatever button you wish to monitor and set the event to "Value Change". If you put this inside a while loop any time the button is pressed, the event structure will run the contents inside the loop. There are a number of options to have the event structure activate.
    *** Warning! I'm probably the last guy you want answering your labVIEW questions, but I figured I might be able to help.

  • How to stop While Loop in Event Structure with same button?

    Hello,
    I have a problem. I want to use one control to activate an event in a event structure, and the same control to terminate a while loop in that event.
    It is possible to use 2 controls to do this, but I need it to be only one.
    Thank you  
    Message Edited by Heinen on 02-19-2009 06:16 AM
    Message Edited by Heinen on 02-19-2009 06:20 AM
    The Enrichment Center is required to remind you that you will be baked, and then there will be cake.
    Solved!
    Go to Solution.

    Hello,
    I have a bit different problem.
    I have a tab control, with several buttons on different pages.
    In the current situation, we can talk about two pages, where one page ("Settings") in the Image, has a START and EXIT button, while second page ("Wait") has an EXIT button.
    In a while loop, I have event structure, which handles events of the START and EXIT buttons of the Settings page. This is fine. But I also want to control the Exit button of the Wait page.
    The control works like this:
    When I click on Start in the Settings page, the front panel shows Wait page and attempts to connect to a datasocket server on the remote computer. If the user wants to stop this process, he can click on Exit on Wait page too. But, this doesn't give any immediate effect. On the even of Start button, the front panel is not locked, so the user can actually click the Exit button on the next page when it's visible. But it's of no immediate effect. Means, what the LabVIEW does is, finishes the execution of event in Start button's click, and while this executes, it doesn't consider the Exit button's refreshed value (shown in Red circle in the block diagram).
    Simple question: Is there any way to check the updated (latest/live) value of a control during some event's execution? Or if I write an Event "Value Changed" for the Exit button and pass it to some variable. Is it the only solution?
    Thanks ahead.
    Vaibhav
    Attachments:
    terminate event_diagram.jpg ‏200 KB
    terminate event_front_1.jpg ‏63 KB
    terminate event_front_2.jpg ‏63 KB

  • While loop in subVI

    Hello
    I have a doubt about using while loops in VI and subVI. I have a VI, with two loop that are executed in parallel, and stoped with the same button, by using property nodes and references. One of the while loop executes a subVI.
    If the Block Diagram of the subvi there is a while loop covering all the code, it's the same to put it in the main VI with another while loop, or it's not necessary?
    it's the same if this subVI has a while loop covering itself that if the subvi doesn't have this while loop because the loop is in the same VI?
    Thank you very much

    Hello,
    I hope I understood you correctly... In general, it's better to use sub VIs to organize and modularize your code. So, if you can separate part of the code into a sub VI, do it.
    And if your main VI is calling the sub VI in a loop, the sub VI executes every iteration of the loop. So, you do not need a loop in sub VI, normally. But it depends on what exactly you are trying to do.
    Use the Execution Highlight mode (the light bulb on the diagram toolbar) to see how the code gets executed, and make changes accordingly.
    Regards,
    Khalid

  • How I break while loop activity in BPEL process

    Hi Guys,
    I want to do a polling action in my bpel process, I put in the polling code in while activity ,
    I try two way to do the break :
    1. use the Flow activity , one sequence for while loop activity , one sequence for timeout flow , put waiting activity in it ,config timeout ... but Flow activity complete only when all branch complete . so it seems there is no way to break Flow from one branch.
    2.use onalarm branch of scope ... put while activity code in a scope activity , create onalarm branch for this scope ,config the timeout time ... but onalarm branch can't bypass the scope sequence...
    Any advice ?
    Thanks
    Kevin
    Edited by: kyi on Oct 29, 2009 1:01 PM

    The on-alarm branch of the scope should work.
    Maybe not so neat but you could try to do a scope with a flow within that. Put in one of the flow-branches a wait. After the wait throw an exception.
    You can catch that exception in a catch branch of the surrounding scope.
    Regards,
    Martien

Maybe you are looking for