473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Input to change program

4
I cant seem to get this right im tring to find the optimal solution and the user imput is 219 how do i get the user to imput a number and what is wrong with my coding am i atleast close HELP


Expand|Select|Wrap|Line Numbers
  1. public class Makechange
  2. {
  3.     public static void main   (String []args)
  4.     {
  5. }    
  6.  {   
  7.     System.out.println (" Please Enter number:" );
  8.  
  9.  
  10.  
  11.     int dollars = amount / 100;
  12.     //number of dollars
  13.     int dollarValue = dollars % 100;
  14.         // value of quarters 
  15.     int amount; 
  16.     amount = dollarsValue;
  17.  
  18.  
  19.     int quarters = amount / 25; 
  20.         //number of quarters
  21.     int quartersValue = quarters % 25; 
  22.         //value of quarters
  23.     amount -= quartersValue;
  24.  
  25.  
  26.     int dimes = amount / 10; 
  27.         //number of dimes
  28.     int dimesValue = dimes % 10; 
  29.         // The value of the dimes
  30.     amount -= dimesValue;
  31.  
  32.  
  33.     int nickels = amount / 5; 
  34.         //number of nickels
  35.     int nickelsValue = nickels % 5; 
  36.         //value of nickels
  37.     amount -= nickelsValue;
  38.  
  39.     int pennies = amount/ 1; 
  40.         //number of pennies
  41.     int penniesValue = pennies % 1;
  42.         //value of pennies
  43.     amount -= penniesValue;
  44.  
  45.  
  46.  
  47.  
  48. System.out.println ("Dollars: " + dollars);
  49. System.out.println ("Quarters: " + quarters);
  50. System.out.println ("Dimes: " + dimes);
  51. System.out.println ("Nickels: " + nickels);
  52. System.out.println ("Pennies: " + pennies);
  53.  }
  54. }
Sep 7 '07 #1
5 1541
JosAH
11,448 Expert 8TB
Your logic w.r.t. dollars, quarters, dimes etc. seems correct; you forgot to read
the 'amount' variable which is crucial here. Have a look at the Scanner class.

kind regards,

Jos
Sep 7 '07 #2
PBJ
4
Your logic w.r.t. dollars, quarters, dimes etc. seems correct; you forgot to read
the 'amount' variable which is crucial here. Have a look at the Scanner class.

kind regards,

Jos
what exactly do you mean my brain is kinda fried been working on this go 8 hours
Sep 7 '07 #3
JosAH
11,448 Expert 8TB
what exactly do you mean my brain is kinda fried been working on this go 8 hours
Exactly as I wrote: you prompt the user to enter a number but there is no code
whatsoever that actually reads a number; I suggested to use a Scanner class
for the reading.

kind regards,

Jos
Sep 8 '07 #4
r035198x
13,262 8TB
I've changed your thread title to something more specific to your problem. Please remember that next time.
Also use code tags everytime when posting code in the forums.
Sep 8 '07 #5
kreagan
153 100+
what exactly do you mean my brain is kinda fried been working on this go 8 hours
It's okay. Whenever someone says: look at [insert name here] class, they mean refer to Java's API. Remember, Java.sun.com is your best Java friend.

Java API

Here you will find this link:

Scanner Class

Scanner class allows you to take input from the user. I would suggest reading the documentation presented in this document because I can't explain it as well as Sun can.

Furthermore, I think there is something funky going on with your brakets. Are you sure it does anything? or even compiles?
Sep 9 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sonny | last post by:
Hi experts, I am writing a small code to read input from a file, for example my input file is: X Y Z 26.0 28.0 0.0 32.0 8.0 0.0 My code is:...
2
by: SophistiCat | last post by:
Hi, I am working on a computational program that has to read a number of parameters (~50) from an input file. The program contains a single class hierarchy with about a dozen member-classes or...
7
by: arkobose | last post by:
hey everyone! i have this little problem. consider the following declaration: char *array = {"wilson", "string of any size", "etc", "input"}; this is a common data structure used to store...
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
4
by: david.w.anderson1 | last post by:
This is a homework assignment. The code works but does not "catch" all the improper input. The requirement is to be able to accept one input currency, which is error checked as a valid entry, and...
1
by: Ray Z | last post by:
I would like to have someone to help me out with my program. Users are able to add items if they wish for the Monthly Claims Charges System. I did not manage to do the calculation part of the...
116
by: dmoran21 | last post by:
Hi All, I am working on a program to take input from a txt file, do some calculations, and then output the results to another txt file. The program that I've written compiles fine for me, however,...
2
by: Killer42 | last post by:
The Input #1 statement simply reads in one line from a text file (in this case you INI file) and places the values from it into one or more variables. So what you are reading in this statement is...
21
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file...
27
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
I have a fully-portable C program (or at least I think I do). It works fine on Windows, but malfunctions on Linux. I suspect that there's something I don't know about the standard input stream...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.