Write a program to input a person’s age and salary. If the age is over 32, then add $1000, otherwise subtract $500 from salary. Finally output the age and new salary. here is the problem
Scanner scan = new Scanner (System.in);
int age, sum, difference, old_salary, new_salary, salary;
System.out.println("Please enter the person age");
age = scan.nextInt();
System.out.println("Please enter the person old salary");
old_salary = scan.nextInt();
System.out.println("Please enter the person new salary");
new_salary = scan.nextInt();
if(age > 32)
{
sum = old_salary + 1000;
System.out.println("your salary is " + salary ); getting a red line underneath 'salary' (the variable salary has nnot be initialized)
}
else if (age<=32)
{
old_salary = new_salary - 500;
difference = old_salary - 500;
System.out.println("your new salary is " + salary); getting a red line underneath 'salary' (the variable salary has nnot be initialized)
System.out.println("your age is " + age);
why do i have to initialized salary, at least when I run the program, I dont think it run properly. when i entered the old salary it say one thing but I think it increased when i entered the new salary, at least i think it should have increased to show the new salary and decreased if the condition in the first statement is false. dont know where I have gone wrong again.