Help. I've been tasked with writing a program that calculates the average temp for a week, getting user input for daily temps, calculating the average and printing out the results. I got that part.
The second part is asking me to print out a message (Too hot!) if the avg is over 100 and (Too cold!) if the average is below 0.
This is where I am stumbling over myself.
here's what I have written:
import java.util.Scanner;
public class AvgTemp
{
public static void main (String args[])
{
int tempM, tempT, tempW, tempR, tempF;
double average;
Scanner input = new Scanner(System.in);
System.out.print("Enter temperature of Monday: ");
tempM = input.nextInt();
System.out.print("Enter temperature of Tuesday: ");
tempT = input.nextInt();
System.out.print("Enter temperature of Wednesday: ");
tempW = input.nextInt();
System.out.print("Enter temperature of Thursday: ");
tempR = input.nextInt();
System.out.print("Enter temperature of Friday: ");
tempF = input.nextInt();
average = calcTemp(tempM, tempT, tempW, tempR, tempF);
System.out.println("The average temperature this week is " +average);
System.exit(0);
}
public static double calcTemp (int tempM, int tempT, int tempW, int tempR, int tempF)
{
double averageTemp;
averageTemp = (tempM + tempT + tempW + tempR + tempF)/5.0;
return averageTemp;
if (averageTemp > 100);
System.out.println("Too hot!");
if (averageTemp < 0);
System.out.println("Too cold!");
System.exit(0);
}
}
As it stands, I am getting an unreachablestatment error in my first "if" statement and a missing return statement error at the end of the program and I cannot understand why.