I put together this program, my first one ever but after I enter the values in the boxes, the output in the end is "0" and not the subtraction. I don't know what i am missing.
import java.util.Scanner;
import javax.swing.JOptionPane;
public class PSEUDOCODE_PROGRAM {
public static void main(String[] args) {
Scanner scnr= new Scanner(System.in);
String applesHad = " ";
String applesNeed = " ";
String orangesHad = " ";
String orangesNeed = " ";
int applesTheyHave = 0;
int applesTheyNeed = 0;
int orangesTheyHave = 0;
int orangesTheyNeed = 0;
int applesToOrder = 0;
int orangesToOrder = 0;
applesToOrder = applesTheyNeed - applesTheyHave;
orangesToOrder = orangesTheyNeed - orangesTheyHave;
//Ask produce buyer how many apples are in stock
applesHad= JOptionPane.showInputDialog(null, "How many apples do you have: ");
applesTheyHave = Integer.parseInt(applesHad);
applesHad= JOptionPane.showInputDialog(null, "How many apples do you need: ");
applesTheyNeed = Integer.parseInt(applesHad);
//Ask produce buyer how many oranges are in stock
orangesHad= JOptionPane.showInputDialog(null, "How many oranges do you have: ");
orangesTheyHave = Integer.parseInt(orangesHad);
orangesHad= JOptionPane.showInputDialog(null, "How many oranges do you need: ");
orangesTheyNeed = Integer.parseInt(orangesHad);
JOptionPane.showMessageDialog(null, "You must order " + applesToOrder + " apples and " + orangesToOrder + " oranges!");
Its very simple you are not calculating applesToOrder
and orangesToOrder
again after user input so they are taking there previous values of 0
, just put these lines just above your last JOptionPane
statement and see the magic.
applesToOrder = applesTheyNeed - applesTheyHave;
orangesToOrder = orangesTheyNeed - orangesTheyHave;