I am really struggling to understand how to write this while loop based on the instructions. Can someone please show me what to do? I already tried to write my own code below and it’s bad.
Here are the instructions:
Write a sentinel controlled while loop that will allow you to calculate the average low temperature for any month. The average temperature should be displayed as a properly calculated double value. Explain why you chose the sentinel value. The code for the input of the initial temperature value is provided.
Here is my code:
int temp = scan.nextInt();
while ()
{
temp = 5.0/9.0 * (temp - 32.0);
System.out.println()
}
You need a condition to stop code execution. The point of the assignment is to choose a value that will stop program execution and why you chose that one.
I tried this code but it’s not working the way I need it to when I run it in repl.it.
Scanner scan = new Scanner(System.in);
int temp = scan.nextInt();
int i = 0;
int total = 0;
double avg = 0.0;
while (i < temp)
{
temp = scan.nextInt();
total = total + temp;
i++;
}
avg = total/temp;
System.out.println(“The average low temperature is:” + avg);
I don’t know and I am really stressed out. This assignment is due today and I don’t know what to do and I just need someone to show me how to code this assignment.
Scanner scan = new Scanner(System.in);
double temp = 0;
double total = 0;
double avg = 0;
int count = 0;
while (temp >= 0)
{
temp = scan.nextDouble();
total += temp;
count++;
}
avg = total / count;
System.out.println(“The average low temperature is:” + avg);
Try this.
Not a Java dev but I have some basic knowledge.
Why less than zero for sentinel value.
Absolute zero is the lowest possible temperature where nothing could be colder and no heat energy remains in a substance. … By international agreement, absolute zero is defined as precisely; 0 K on the Kelvin scale, which is a thermodynamic (absolute) temperature scale; and –273.15 degrees Celsius on the Celsius scale.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
I have added [spoiler] and [/spoiler] tags on the line above and below your solution code.
Hello, I’m sorry she said that it is urgent thats why I posted the solution, but we are having a conversation right now. I did tell her next time to research way ahead of time of the assignment.