107 307
Assignments Done
98.9%
Successfully Done
In March 2023

# Answer to Question #209360 in C# for olivia

Question #209360

Write a program that reads in 10 midday temperatures for Port Elizabeth, for 10 consecutive days. Only temperatures higher than 0 and less than 45 are valid (working with integer values for temperatures). It must calculate and display the following:  The warmest temperature  The average temperature.  The number of days that the temperature was higher than 30.

Display the temperatures in the array e.g All the temperatures in the array are: 22 26 17 19 20 39 44 37 30 16

1
Expert's answer
2021-06-22T02:38:01-0400
using System;
using System.Linq;

namespace PortElizabeth
{
public class Program
{
public static void PrintLine()
{
Console.WriteLine(new string('-', 30));
}

public static void Main()
{
var temperatures = new int[10];
var counter = 0;
var temp30count=0;
Console.WriteLine("Please, enter 10 midday temperatures for Port Elizabeth:");

while (counter < 10)
{
int input = Convert.ToInt32(Console.ReadLine());
if(input>0 && input<45)
{
Console.WriteLine($"Number accepted!"); PrintLine(); temperatures[counter]=input; counter++; if(input>30) temp30count++; continue; } Console.WriteLine("Error! Please, enter a valid temprature(higher than 0 and less than 45)"); } Console.WriteLine("All temperatures recieved."); PrintLine(); Console.WriteLine($"The warmest temperature: {temperatures.Max()}");
Console.WriteLine($"The average temperature: {temperatures.Average()}"); Console.WriteLine($"The number of days that the temperature was higher than 30: {temp30count}");

PrintLine();

Console.Write("All the temperatures in the array are:");
foreach(var temp in temperatures)
Console.Write(\$" {temp} ");
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

#### Comments

No comments. Be the first!

### Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS