Question

I need help with the following assignment: Write an application named DailyTemps that continuously prompts a...

I need help with the following assignment:

Write an application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message:

Valid temperatures range from -20 to 130. Please reenter temperature.

Before the program ends, display the number of temperatures entered and the average temperature.

This is what I currently have:

using System;

class Program
{
static void Main(string[] args)
{
int number;
int sum=0;
  
Console.WriteLine("Please enter your series of high temperatures and enter 999 when you are done.");
do{
number = int.Parse(Console.ReadLine());
for(int i=1;i<-20 || i>130;i++)
{
Console.Write("Valid temperatures range from -20 to 130. Please reenter temperature.");
}
for(number!=999)
{
sum+=number;
}
else
break;
}
while( number= 999);

// Now sum has accumulated the sum of all numbers excluding 999
Console.WriteLine("The sum is {0}", sum);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C# Program:

using System;

class Program
{
static void Main(string[] args)
{
int number=0;
int sum=0;
int temp;
  
Console.WriteLine("Please enter your series of high temperatures and enter 999 when you are done.");
do{
temp = int.Parse(Console.ReadLine());
if(temp==999)
break;
if(temp<-20 || temp>130)
Console.WriteLine("Valid temperatures range from -20 to 130. Please reenter temperature.");
else{
sum+=temp;
number++;
}
}while(true);

// Now sum has accumulated the sum of all numbers excluding 999
Console.WriteLine("The sum is {0}", sum);
Console.WriteLine("Number of temperatures entered is {0}",number);
Console.WriteLine("Average temperature is {0}",(float)sum/number);
}
}

Output:

Add a comment
Know the answer?
Add Answer to:
I need help with the following assignment: Write an application named DailyTemps that continuously prompts a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What I need: Write a program named Averages that includes a method named Average that accepts...

    What I need: Write a program named Averages that includes a method named Average that accepts any number of numeric parameters, displays them, and displays their average. For example, if 7 and 4 were passed to the method, the ouput would be: 7 4 -- Average is 5.5 Test your function in your Main(). Tests will be run against Average() to determine that it works correctly when passed one, two, or three numbers, or an array of numbers. What I...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel –...

    Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel – sentinel is used to indicate the end of input and must not to be considered as the valid data for the computation). Perform the following operations for the integers entered by the user. Display the sum of the numbers less than 100 Display the smallest of the positive integers Display the largest of the negative integers Display how many integers are between 100 and...

  • Can I get the answers in Java, please? Write an application that prompts a user for...

    Can I get the answers in Java, please? Write an application that prompts a user for the number of years the user has until retirement and the amount of money the user can save annually. If the user enters a 0 or a negative number for either value, reprompt the user until valid entries are made. Display the amount of money the user will have at retirement. The total amount of money the user will have can be calculated with...

  • Write a C# program (Integer Math Calculator, the programming requirements are as follows: When typing in...

    Write a C# program (Integer Math Calculator, the programming requirements are as follows: When typing in 3+4, 10-5, 12*12, 15/5 from console, the program should give the right answers on screen like 7, 5, 144, 3. This is what I have so far: namespace ConsoleApplication3 { class Program { static void Main(string[] args) { String input; do { Console.Write("Type int values to calulate or stop to exit: "); input = Console.ReadLine(); if (input.ToLower() != "stop") { char[] delimiters = {...

  • For the following C# program: Let’s add one more user defined method to the program. This...

    For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Have the user enter an integer nbetween 100 and 999.  If the integer does not satisfy the...

    Have the user enter an integer nbetween 100 and 999.  If the integer does not satisfy the given criteria (not in the correct range), or if the entered value is not an integer (use method hasNextInt(). have the user reenter an integer Create an integer kthat is the reverse of n.   NOTE: k must be an integer Display k. Repeat The program will stop when the user enters 0 (create a sentinel). Example of the programs output: Please enter an integer between...

  • i need help fixing my code. here is the assignment: Make a class that contains the...

    i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...

  • PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from...

    PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from tony gaddis starting out with java book. I have included the screenshot of the problems for reference. I need HELP implementing these two problems TOGETHER. There should be TWO class files. One which has TWO methods (one to implement problem 8, and one to implement problem 9). The second class should consist of the MAIN program with the MAIN method which calls those methods....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT