I have this but there is an error, I don’t get it :(. I’m relatively new to Java.
package hw; import java.util.Scanner; public class Problem1 { public static void main (String [] args) { int cost; int number; double cost_unit; double total; Scanner entrada = new Scanner(System.in); System.out.println('Please enter the cost of the product.'); cost = entrada.nextInt(); while (cost>0){ System.out.println('Please enter the amount of units to be sold'); number = entrada.nextInt(); if (number>0); cost_unit = cost * 1.4; total = cost_unit*number; System.out.printf('Cost per unit will be $ %d\n',cost_unit); System.out.printf('Cost per unit will be $ %d\n',total); } } }
// I just want the user to enter the cost for a product, give a number of units to be ordered, and I want the program find out the final price of the product with a 40% profit.
In printf,
%dis for a signed decimal integer, whereascost_unitandtotalare doubles. You should use%finstead.