
-----------------------------------
indianstorm
Sat Nov 06, 2004 11:30 am

Help plz
-----------------------------------
Write a program that reads in a number of cents. The program will write out the number of dollars and cents, like this: 

D:\users\default>java  Dollars
Input the cents:
324
That is  3 dollars and 24 cents.

(For this program you will use integer arithmetic and will need to avoid floating point arithmetic. Review the integer remainder operator % if you are unsure how to proceed.) 

___________________________________________________________


import java.io.*;
class Areaofacircle
{
    public static void main (String[] args) throws IOException
    {
        InputStreamReader inStream = new InputStreamReader (System.in);
        BufferedReader stdin = new BufferedReader (inStream);

        String inData;
        double num;
        double beamer, streamer;

        System.out.println ("Enter the amount of money:");
        inData = stdin.readLine ();


        num = Integer.parseInt (inData);
        
        streamer= num % 100;
        beamer = num - streamer / 100;

        System.out.println ("The money given was " + inData + " which is " + beamer + " dollars and " + streamer + " cents ");

    }
}

____________________________________________________________

Plz help me witht that

-----------------------------------
indianstorm
Sat Nov 06, 2004 11:46 am


-----------------------------------
nvm i got it

__________

import java.io.*;
class Calcofmoney
{
    public static void main (String[] args) throws IOException
    {
        InputStreamReader inStream = new InputStreamReader (System.in);
        BufferedReader stdin = new BufferedReader (inStream);

        String inData;
        double num;
        double beamer, streamer;

        System.out.println ("Input the amount of money:");
        inData = stdin.readLine ();


        num = Integer.parseInt (inData);
        
        streamer= num % 100;
        beamer = (num - (streamer))/100;

        System.out.println ("That is " + beamer + " dollars and " + streamer + " cents ");

    }
}

-----------------------------------
wtd
Sat Nov 06, 2004 3:16 pm


-----------------------------------
You declare "num", like thus:

double num;

But you use it as an integer:

num = Integer.parseInt(inData);

And you use the modulus operator on it:

streamer = num % 100;

Clearly "streamer", "beamer", and "num" should be declared as integers, not doubles.

Also, in Java you don't need to declare all of your variables at the beginning of a function.  With no other changes made to correct it: 

import java.io.*;
import java.lang.*;

class Calcofmoney
{
   public static void main (String[] args) throws IOException
   {
      InputStreamReader inStream = new InputStreamReader (System.in);
      BufferedReader stdin = new BufferedReader (inStream);

      System.out.println("Input the amount of money:");
      String inData = stdin.readLine();

      double num = Integer.parseInt(inData);

      double streamer= num % 100;
      double beamer = (num - (streamer))/100;

      System.out.println ("That is " + beamer + " dollars and " + streamer + " cents ");
   }
}

-----------------------------------
wtd
Sat Nov 06, 2004 3:19 pm


-----------------------------------
By the way, it's nice to see you using standard Java.
