Im just a beginner and anything would be helpful. So basically this program asks a question and depending on input, affects the price of tshirts. Also it asks how many tshirts wanted to be purchased also affecting the price. It keeps on running until "exit" is typed.
The problem I have is that I want the output to have the total sales and other info that was accumulated from the if/else if statements before. But when I compile it says local variable may not have been initialized. Any help would be much appreciated
import java.util.Scanner;
class ScannerTest{
public static void main (String args[]){
int b, c;
String endProgram = "exit";
String userInput;
java.util.Scanner input = new java.util.Scanner(System.in);
do{
System.out.println("\n Welcome to the SAC t-shirt sales software");
System.out.println("\n Does the student have an activity fee? Yes/No/Exit");
userInput = input.nextLine();
if (userInput.equalsIgnoreCase("yes")){
System.out.println("How many Tshirts do you want to buy?");
b = input.nextInt();
input.nextLine();
System.out.println("Cost:" + b*5 + " dollars");
}
else if(userInput.equalsIgnoreCase("no")){
System.out.println ("How many Tshirts do you want to buy?");
c = input.nextInt();
input.nextLine();
System.out.println("Cost:" + c*6 + " dollars");
}
}while (!userInput.equalsIgnoreCase(endProgram));
System.out.println ("Activity Card Sales:" + b + "Non-activity Card Sales:" + c + "Total Money Collected" + ((b*5)+(c*6)));
input.close();
}
}