#Flow chart to Java.

1 messages · Page 1 of 1 (latest)

hexed cradle
#

Hello! I was given a flow chart with no instructions on how to turn it to code. It's meant to be super basic because all we have really learned are scanners, strings, while, if, those kinds of things. I have been working on this for almost two days and keep striking out. I have included a screenshot of what I have figured out to so far.

hollow widgetBOT
#

This post has been reserved for your question.

Hey @hexed cradle! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

half scroll
#

maybe use elif bro

#

also scanner not initalised

uncut flowerBOT
#

"""
//name this file program2 or it will not work

import java.util.Scanner;


public class program2 {
   public static void main(String[] args) {
       // Create a Scanner object to read input
       Scanner scanner = new Scanner(System.in);

       // Prompt the user for an input
       System.out.print("Enter an amount of change (0-99): ");
       int amount = scanner.nextInt();

       // Calculate number of quarters
       int quarters = amount / 25;
       amount %= 25; // quarters is worth 25

       // Calculate number of dimes
       int dimes = amount / 10;
       amount %= 10; // dimes is worth 10

       // Calculate number of nickels
       int nickels = amount / 5;
       amount %= 5; // nickel is worth 5

       //there may be remaining amount, here I add a nickel if there is
       if (amount != 0){
           nickels += 1;
       }

       // Display the result
       System.out.println("Quarters: " + quarters);
       System.out.println("Dimes: " + dimes);
       System.out.println("Nickels: " + nickels);
   }
} ```
"""

This message has been formatted automatically. You can disable this using /preferences.

half scroll
#

For the zero to exit part you need input validation of different type (string vs int), not easy for your level, instead of "ZERO" maybe 0 (as in integer) and use a if statement would be the best, I overlooked this part when I was recreating your code, but it's easy to add