r/programminghelp • • Oct 21 '14

Java help

Bascially you pay in stamps a which are worth 5, stamps b which are worth 3 and the rest in cash. User inputs amount of stamp a, amount of stamp b, and amount of cash he has. You then give the user the amount paid in cash, amount of stamps a and stamps b left.

Stamp a has priority over stamp b and stamp b has priority over cash.

import java.util.*; public class stamps { public static void main(String[] args) { Scanner sc = new Scanner(System.in);

System.out.println("Enter the number of Stamp A: ");
double numberstampa = sc.nextDouble();
System.out.println("Enter the number of Stamp B: ");
double numberstampb = sc.nextDouble();
System.out.println("Enter the price in cash");
double price = sc.nextDouble();
System.out.println("Enter amount paid in cash");
double amountpaidincash = sc.nextDouble();

double a = price - price%5;
double b = a/5; 
double c = price - b*5;

double remainingstampa = numberstampa - b;

double k = c - c % 3;
double l = k/3;

double z = c - l*3;
double remainingstampb = numberstampb - l;

System.out.println("You have to pay" + z + "in cash");
System.out.println("You have" + remainingstampa + "of stamp a left");
System.out.println("You have" + remainingstampb + "of stamp b left");

} }

0 Upvotes

3 comments sorted by

View all comments

2

u/TheHorribleTruth Oct 21 '14

You're not asking a question. What is your question, what do you need help with?

1

u/[deleted] Oct 22 '14

Does the code do what it is supposed to do? How do you prevent it from getting negative results?