Answer to Question #212311 in C# for Melusi

Question #212311

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.


1
Expert's answer
2021-06-30T13:42:36-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q212311
{
    class Program
    {
        static void Main(string[] args)
        {


            int warmestTemperature =-1;
            double averageTemperature = 0;
            int sumTemperatures = 0;
            int warmDaysCounter = 0;
            for (int i = 0; i < 10; i++)
            {
                int temperature = -1;
                while (temperature < 0 || temperature > 45)
                {
                    Console.Write("Enter temperature for day {0} [0-45]: ", (i + 1));
                    if (int.TryParse(Console.ReadLine(), out temperature) == false)
                    {
                        temperature = -1;
                    }
                }
                sumTemperatures += temperature;
                if (temperature > 30) {
                    warmDaysCounter++;
                }
                if (temperature > warmestTemperature)
                {
                    warmestTemperature=temperature;
                }
                
            }
            averageTemperature = sumTemperatures / 10.0;
            Console.WriteLine("The warmest temperature: {0}", warmestTemperature);
            Console.WriteLine("The average temperature: {0}", averageTemperature);
            Console.WriteLine("The number of days that the temperature was higher than 30: {0}", warmDaysCounter);


            Console.ReadLine();
        }


    }
}




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