Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Convertinga an old turing program to java..
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Insectoid




PostPosted: Thu Oct 02, 2008 2:17 pm   Post subject: Convertinga an old turing program to java..

we all remember this thread, right? http://compsci.ca/v3/viewtopic.php?p=159343&highlight=#159343

Well, This year, I have to do the same thing in Java. I figured, heck, I'll just use the same code and convert it to java! unfortunately, this comes with the same glitches as a year ago. I looked over it, but can't find the issue (Terrible at debugging I am). Any help. (holy nostalgia...). Anyways, the point is, it gives me the wrong ammount of change.

Super messy code (Very much miss F2 from Turing...)
code:



public class change_maker {

public static void main(String [] args) {

int money  = 20000;
int change; //The remaining change;
int total = 500;

int twent = 2000;
int ten = 1000;
int five = 500 ;
int toon = 200 ;
int loon = 100 ;
int quart= 25 ;
int dime = 10 ;
int nick = 5;
int penn = 1 ;

int totaltwent ;
int totalten ;
int totalfive ;
int totaltoon ;
int totalloon ;
int totalquart ;
int totaldime ;
int totalnick ;
int totalpenn ;





change = money - total;



totaltwent = change / twent;
change = change % twent;

totalten = change / ten;
change = change % ten;

totalfive = change / five;
change = change % five;

totaltoon = change / toon;
change = change % toon;

totalloon = change / loon;
change = change % loon;

totalquart = change / quart;
change = change % quart;

totaldime = change / dime;
change = change % dime;

totalnick = change / nick;
change = change % nick;

totalpenn = change;

System.out.println ("Your change is:" );
if (totaltwent > 0) {

    System.out.println ( totaltwent+ " twenties");
}


if (totalten > 0) {
            System.out.println ( totalten+ " tens");
}


if (totalfive > 0) {
    System.out.println ( totalfive+ " fives");
}


if (totaltoon > 0) {
    System.out.println ( totaltoon+ " toonies");
}


if (totalloon > 0) {
    System.out.println ( totalloon+ " loonies");
}


if (totalquart > 0) {
    System.out.println ( totalquart+ " quarters");
}

if (totaldime > 0) {
    System.out.println ( totaldime+ " dimes");
}


if (totalnick > 0) {
    System.out.println ( totalnick+ " nickels");
}


if (totalpenn > 0){

    System.out.println ( totalpenn+ " pennies");
}
 
           
    }
   
   
}
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Thu Oct 02, 2008 2:33 pm   Post subject: RE:Convertinga an old turing program to java..

Sample input and output would be extraordinarily helpful in solving this problem.
Insectoid




PostPosted: Thu Oct 02, 2008 2:53 pm   Post subject: RE:Convertinga an old turing program to java..

Sorry, the school had ended before I finished posting, so it was rather rushed. Input, for the moment, is static and pre-defined.

The objective is to input an amount of money as well as the price of an item and have it output the change using the minimum number of coins/bills possible. As of now, a total value of 20.00 with an item price of 5.00 will output something like 9 twenties, 1 ten, and one five. If I remember correctly. Yes, the variable names are terrible (I did the original within the first month of programming). I found a whole bunch of mistakes in it already, but I fixed them. The nice thing here is, Java AND Turing people can help me! lol (really, laughing right now)

Thanks.
HellblazerX




PostPosted: Thu Oct 02, 2008 3:33 pm   Post subject: RE:Convertinga an old turing program to java..

I just ran your program and it looked fine to me.
Insectoid




PostPosted: Fri Oct 03, 2008 1:14 pm   Post subject: RE:Convertinga an old turing program to java..

You sure you didn't get this?:

code:

9 twenties
1 tens
1 fives


Because that is not fine. This totals to $195 change after entering $20.00.

EDIT: Oh, crap. The problem was not my code, but my static input. I had it set to 20000 cents ($200) rather than 2000 cents ($20). I must say, this is the absolute stupidest mistake of my life. Wow...
gitoxa




PostPosted: Fri Oct 03, 2008 5:36 pm   Post subject: Re: RE:Convertinga an old turing program to java..

insectoid @ Fri Oct 03, 2008 1:14 pm wrote:
I must say, this is the absolute stupidest mistake of my life. Wow...


Then you've got a lot of catching up to do. Smile
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: