How do you count how many times a if/when/for statement runs?

So this new program I'm trying to write is a changemaker (in euros for some reason). You enter a price of a product, amount paid, and it computes how much change you should get back in the form
[number] x 2-euro
[number] x euro
[number] x 20-cent
etc
Where the number is the number of that kind of coin they should get back.
Right now, I have it so that you enter price, and amount paid, and then I have a series of while statements that go like..
while (surplus > 2.00);
while (surplus > 1.00);
etc. If the surplus > 2, I want to add 1 2-euro coin to the count, subtract 2, and then recheck the amount and either add another 2-euro or go onto the next coin. Only thing is, I don't know how to count how many times a while statement ran until it was false. Or I could be looking at this the wrong way entirely. What's the best way to go about a program like this?

Well I finally figured it out with lots of help from other students in the class. It was much easier than it appeared to be. Thanks for the hints everyone (especially joker for doing the coding for it) wow :D much appreciated ^^
Heres the code that I came up with and it works matches the assignment's example:
import java.util.* ;
public class ChangeMaker {
     private static int changeA [] = new int [7] ;
     private static float changeVar[] = new float [7] ;
     private static int changeVarNumb[] = new int [7] ;
     private static String changeNames[] = new String [7] ;
     // initialize Scanner
     private static Float getInput (String prompt){
          System.out.print (prompt.concat(" ")) ;
          Scanner sc1 = new Scanner (System.in) ;
          return (sc1.nextFloat ()) ;
     // put the change variables and change names into arrays
     private static void moneyArray (){
          changeVar[0] = (float) 2.0 ;
          changeVar[1] = (float) 1.00 ;
          changeVar[2] = (float) 0.20 ;
          changeVar[3] = (float) 0.10 ;
          changeVar[4] = (float) 0.05 ;
          changeVar[5] = (float) 0.02 ;
          changeVar[6] = (float) 0.01 ;
          changeVarNumb[0] = 2 ;
          changeVarNumb[1] = 1 ;
          changeVarNumb[2] = 20 ;
          changeVarNumb[3] = 10 ;
          changeVarNumb[4] = 5 ;
          changeVarNumb[5] = 2 ;
          changeVarNumb[6] = 1 ;
          changeNames[0] = (String) "Euro" ;
          changeNames[1] = (String) "Euro" ;
          changeNames[2] = (String) "Cent" ;
          changeNames[3] = (String) "Cent" ;
          changeNames[4] = (String) "Cent" ;
          changeNames[5] = (String) "Cent" ;
          changeNames[6] = (String) "Cent" ;
          return ;
     // calculate the change the user is going to receive
     private static void calcChange(float diffAmount) {
          for (int i = 0; i < changeVar.length ; i++) {
               if (diffAmount > changeVar) {
                    changeA[i] = (int)(diffAmount / changeVar[i]);
                    diffAmount = diffAmount - (changeA[i] * changeVar[i]) ;
                    System.out.println(changeA[i] + " x " + changeVarNumb[i] + " " + changeNames[i]) ;
          return;
     // output
     public static void main(String[] args) {
          float itemPrice = getInput("Enter product price: ") ;
          float amountTendered = getInput("Enter amount paid: ") ;
          float diffAmount = amountTendered - itemPrice ;
          System.out.println() ;
          System.out.println("Your change is " + diffAmount + " euros") ;
          moneyArray() ;
          calcChange(diffAmount) ;
And the output looks like this:
Enter product price:  2.32
Enter amount paid:  5.00
Your change is 2.68 euros
1 x 2 Euro
3 x 20 Cent
1 x 5 Cent
1 x 2 Cent
1 x 1 Cent                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How many times can I try for restriction passcode in ipad

    HI
       I have forgotten restriction passcode and have already tried 12 times. Now it allows me to attempt after every 1 time. Though I have forgotten my password but I have a finite set of passwords. I am sure I will be able to crack after some 15/20 more times. Now do I stand a chance of my IPAD device permanently disabled after a certain no of times. I am ok with trying after every 1 hour as many times as possible but dont want to enter into a scenario where my device is permanantly locked. I dont have an itunes back up also so restoring from itunes is not there. Can I change the time and go on fooling the system?
    Regards
    S Choudhury

    If you are talking about Parental Control type of restrictions on the iPad, I believe that to be entirely iOS software level. You have 6 attempts before it locks you out for a minute. It then increases the locked-out time after further failed attempts. Since you have two failed attempts, it should let you have four more without consequence, which, if one goes through, all is well, if not, you will be locked out, before you can do a 7th attempt for 1 minute - to start with.If you fail the 7th time, it will increase the time to 5 minutes.

  • TS1717 iTunes "Terms and Conditions Have Changed Before you can proceed you must accept the terms and conditions" is on an infinite loop.  No matter how many times I agree, when I go to update my apps the terms and conditions have changed link reappears.

    Can anyone help me?  Suddenly (i.e. just a few minutes ago) this problem has appeared.  I attempted to update two apps on my iPad.  The Terms and Conditions agreement comes up, I read the terms and conditions, I agree to them, I click AGREE, it disappears, I reclick on update and the Terms and Conditions agreement appears and we start the mobius strip all over again.  I tried to see if it was just on my iPad by trying to download a new app on my iPhone.  same problem.  Anyone have advice on how to resolve this issue?  Oh, and of course, Apple has declared my two new devices to be out of warranty and want me to pay to ask how to fix a problem caused by their own software.  Lovely.  so helpful.  Hey Cupertino ... are you paying attention?  I might start tweeting about this.

    I updated the software on my iphone4 tonight and ran into this same endless loop - "itunes terms & conditions have been changed" - go to itunes, aceept - back to the "T&C have been changed message" with no ability to do anything in the app store until I accepted the new terms.
    While not a very direct solution, I was able to finally accept the terms in a way that seem to register with apple by making a purchase through iTunes on my computer. This forced me through updating my payment information and updating my iTunes software to the latest edition (which I had not yet taken the time to do).  After doing both of these, iTunes took me through the terms & conditions on two separate pages, but ultimately allowed me to purchase my song.  Once I completed these steps, it fixed the problem on my phone, so now I can update my apps and download new ones without running into that loop.
    Hope this helps!!!

  • I need hepl about the unlocking, im from bolivia and im going to the united states but im going to be just one day at the mall at orlando and i need to know how many time takes the unlocking for Bolivia an if it has a extra cost,please help

    im tlaking about the iphone 4s, im going to be really grateful for the help bye

    Please clarify what you mean. Do you already have an iPhone? If so, and it came from the US and is (presumably) carrier locked, you're out of luck. NONE of the US carriers will unlock iPhones. There are no exceptions.
    The unlocked iPhone 4S is not yet available in US Apple retail stores. All phones sold at retail in the US are currently carrier locked.

  • How many times can you download a song on iTunes and have it count?

    I'm wondering. Someone I like have released a song on iTunes and I wanna support them and I dont mind spending a few bucks on them.
    So how many times can I download a song and still have it count as an individual purchase? And what about gifting?
    thanks.
    -andy.

    As Polydorus said, get only one download per purchase for anything you buy from the iTunes Store other than iOS apps or iBooks. I'm not sure what you mean by "individual purchase" or what you are asking in reference to gifting.
    Regards.

  • How many times can you burn a song to CD?

    Once you've downloaded a song from iTunes, is there a limit to how many times you can then burn it to a CD?
    Dell   Windows XP  
    Dell   Windows XP  

    The limit is not by song, it's by playlist. Any playlist containing purchased music can burned up to a maximum of 7 times. Once you reach the max burns for a specific playlist, simply change the order of the playlist by one or two songs & that 7 count will re-set.

  • Counting how many times my app has been opened

    I want to be able to count how many times a user has opened my application, and so every time the application launches, this number is added by one.
    Does anyone know how I store a long-time variable like this that will still need to be available across different runs of the application? I imagine this value would be stored in the application's preference file in Library, but I don't know how to do this.
    Can any of you please lend me some advice/code to achieve this (I am using Objective-C)?
    Thanks in advance,
    Ricky.

    Hi.
    It has been a while - but I finally got around to slapping some code together. I have successfully created and retrieved the value from the preference file, but for some reason, adding 1 to my value each run is not working. It only adds by one after each BUILD. So I have to rebuild it every time I want it to increment. See my code below;
    [NSUserDefaults init];
    int numberOfTimes;
    numberOfTimes = [[NSUserDefaults standardUserDefaults] integerForKey:@"used"];
    numberOfTimes = numberOfTimes++; //It is that that is not working.
    [[NSUserDefaults standardUserDefaults] setInteger:numberOfTimes forKey:@"used"];
    NSLog (@"%d", [[NSUserDefaults standardUserDefaults] integerForKey:@"used"]);
    I can't seem to stop anything wrong, but then again it is late.
    Do any of you see any errors here?
    Thanks,
    Ricky.

  • Keeping count of how many times a case structure has been entered.

    I have a "Case" structure (when a button is pressed, it is "case True").
    I want to keep track of how many times this "case True" has been entered.
    How can I do this?
    Solved!
    Go to Solution.

    For that you need to have a shift register or a feedback node and keep counting whenever the case structure case is executed the count will be increased by one see the attached snippet.
    Good Luck
    The best solution is the one you find it by yourself
    Attachments:
    CaseStructure count.png ‏10 KB

  • Cycle counting - How many times an item has been counted?

    Hallo Gurus,
    do you know if there's a way to know how many times an item has been counted during the year?
    Thank you very much indeed.
                Mick

    Hi Mick,
    Check the below links. Hope they will help you.
    http://help.sap.com/saphelp_snc70/helpdata/EN/4c/c1b4b55b912a4ae10000000a42189b/content.htm
    http://help.sap.com/saphelp_46c/helpdata/en/4d/2b8e3d43ad11d189410000e829fbbd/content.htm
    Regards,
    Shilpa

  • Hey! On excel I want to count how many time a text come back in the spreadshit (sum) thx, hey! On excel I want to count how many time a text come back in the spreadshit (sum) thx

    Excel:
    line of cellule with 3 different text. I want to count have many time a text come in the line... Thx for helping me, it is for my job!!

    Hopefully I am understanding your question.
    A typical way to count how many times a word appears in a line of text in a cell is to substitute spaces for the word, one less space than the length of the word. Example:
    A1 has the string "brown red brown green"
    A2 =LEN(A1) - LEN(SUBSTITUTE(A1,"brown","    "))  
    "brown" has five letters so there are four spaces in the substitution text)
    If you want to do several cells at once, counting the total number of times the word appears, concatenate the cells with a space between them
    A1 and A2 have text in them
    A3 =LEN(A1&" "&A2) - LEN(SUBSTITUTE(A1&" "&A2,"brown","    "))

  • Something to count how many times form has downloaded

    Hi there.
    DW CS3, PHP mySQL
    I want to put on my site a PDF document that people can
    download.
    I don't want to link this to my mySQL DB for the records to
    be added in the
    DB.
    But, I want to see how many times this document has been
    downloaded.
    It's almost like "autonumber" in Access.
    I will really appreciate any advise and direction on how to
    accomplish
    this.
    Thanx so much.
    Deon

    Thanx Joe, I will check it out.
    I'm quickly building the download page.
    Deon
    Joe Makowiec <[email protected]> wrote in
    news:[email protected]:
    > On 14 Oct 2008 in macromedia.dreamweaver, Deon H wrote:
    >
    >> I want to put on my site a PDF document that people
    can download.
    >> I don't want to link this to my mySQL DB for the
    records to be added
    >> in the DB.
    >>
    >> But, I want to see how many times this document has
    been downloaded.
    >> It's almost like "autonumber" in Access.
    >> I will really appreciate any advise and direction on
    how to
    >> accomplish this.
    >
    > It's available in your logs. Just do a search for
    "myfile.pdf", and
    > look for lines which have a 200 status code. (Status
    code of 206
    > indicates a resumed download; you don't want to count
    those.) A
    > recent sample; details changed to protect the guilty:
    >
    > 192.168.4.246 - - [14/Oct/2008:01:56:04 +0000] "GET
    > /documents/town20080911.pdf HTTP/1.1" 200 20101
    > "
    http://www.example.org/minutes.asp"
    "Mozilla/4.0 (compatible; MSIE
    > 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"
    192.168.4.246 - -
    > [14/Oct/2008:01:56:04 +0000] "GET
    /documents/town20080911.pdf
    > HTTP/1.1" 206 18572 "-" "Mozilla/4.0 (compatible; MSIE
    6.0; Windows NT
    > 5.1; SV1; .NET CLR 1.1.4322)"
    >
    > The first field is the IP address that the request came
    from
    > The second is date/time (in this case, in GMT)
    > The third is the request with protocol
    > The fourth is status code[1] followed by bytes
    transferred
    > The fifth is referrer; the sixth is user agent
    >
    > More information:
    http://www.w3.org/TR/WD-logfile.html
    >
    > [1]
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
    >

  • How to count how many times the caller calls by using UCCX script?

    Hi there,
    My customer wants to do a few changes for their script as below:
    At the beginning of the script they are planning to add a new menu item, it will announce their new privacy policies and to continue the user must press the number one to continue to the Welcome.  If they do not press 1 then the message should repeat itself and if they again do not press 1 they should be transferred over to a live operator who will explain things and then be able to transfer them back to the message so that they can press 1 and continue.
    I modified their script as attached file, but i don't know how to count how many times the caller calls in "Get Reporting Statistic".
    Any helps would be appreciated.
    Thanks.

    Hi Aaron,
    At beginning, i want to use a variable to get number of mistake for the same caller, then we will send the call to right place to fulfill the customers' needs. 
    Do you have any suggestion for the new posted script?
    Thanks.

  • How many times can you transfer itunes to ipod?

    After I accidentally erased my itunes from my ipod i tried to re-transfer them from itunes library. Can I do this more than 1 time or is one time the limit on songs purchased from itunes?

    Songs purchased on the iTunes Music Store can be copied to an unlimited number of computers. However, only five computers at a time can play your purchased music. There is no limit on how many times a song is transferred to your iPod as you do not need to authorise your iPod just the computer that it links to.

  • How many times can you reinstall Mountain Lion?

    Since I bought the Early 2013 15" MacBook Pro retina laptop used only 17 battery cycles on it now (2.7 with 16GB ram running Mt. Lion) computer I have not reset it. I spoke to Apple and it is registered in my name, I made a new Admin. account and password and Apple had me delete the original owners. I took off anything he had left on it. Applecare also I bought in my name. Apple said I didn't have to reset it and would be fine so I left it. They deauthorized the previous iunes account and the previous owner gave me his ID to deauthorize the computer. It was already deauthorized when I checked. He then changed his password for his security. It runs beautifully and has a Samsung screen.
    I deleted the iLife apps and were going to buy them in my name (as his ID came up for updates) but now can't redownload in my name as it says I need Maverick OSon it to do so. I left the Mountain Lion 10.8.5 on it. If I contact Apple will they give me a redemption code for my name or how do I get older versions?
    If I reset to new how many times am I able to reinstall Mountain Lion? If I decide to sell it later will I be able to reset it again with no problem for the new owner?
    Thank you for your help. This forum is a source for many of us new owners to solve things.

    As long as you do the download with your Apple ID, it'll be in your name. Reverting back can be a little involved. If you have that in mind, you should make a full backup of your clean install of ML and save it somewhere. Then you can just copy the image back with Carbon Copy Cloner. External drives are cheap, that's how I'd do it.

  • How many times can you resend an iTunes Gift Card?

    Tried sending an iTunes gift card to a @facebook account but the recipient hasn't received it.
    Is it possible to send to another of their @facebook accounts and if that also fails then to a conventional account?
    I guess my question is how many times can you resend on Gift Card and to how many different email accounts?

    To use an iTune Gift Card to buy books...
    Open iTunes on your computer and click on the iTunes Store.
    You'll need to be signed in...
    Click on the little House icon in the dark gray bar across the top. (or Shift+Command+H)
    On the right side of the page under Quick Links click Redeem and enter your code.
    Then it will show your credit balance in the dark gray bar across the top next to your account name to let you know how much you have to spend.
    Then as you buy books, it'll deduct from the credit balanace.
    There is a distinction between, iTunes Gift Card and Apple Gift Card.
    Apple Gift Card: can be used to purchase Apple hardware and accessories at any Apple Retail Store, the Apple Online Store...
    iTunes Gift Card: To give music, movies, TV shows, apps, books, or anything on the iTunes Store, the App Store, the iBooks Store or the Mac App Store, select an iTunes Gift Card

Maybe you are looking for

  • Set up Mac Mail to not count secondary account

    I would like to set up my mail so that my secondary account only shows mail from one specific sender. If not possible at least how do I exclude account from counting mail in dock.

  • Q4 2014 Bundles

    Nowadays, when you buy a gaming notebook from MSI, chances are you'll end up with a little something on the side, apart from the notebook and the usual accessories. The tricky bit is that what extras you get vary quite wildly from region to region, m

  • Some dba and OS related confusions

    Hi All, I have few doubts related to database and OS perspective. Could pelase someone let remove my these doubts and clarify below questions: Qus1: Can we have two listener.ora file with same default port number 1521? Qus2: Why do we create two grou

  • Delivery cannot be invoiced

    Hello experts, After selecting Billing Type as 'Invoice-Del rel' and entering the delivery number in the document field, I get the following error: "The document is not relevant for billing". The item categories on the material are delivery relevant.

  • Datawarehouse school project

    Hi, I'm student and I want to do a school project with Oracle. My project is about datawarehouse. I want to build and work with oracle database and oracle data mining with datawarehouse databases. I want to know if I can download oracle database and