I created this little application which calculates an average of temperatures based on values given by user. I am trying to create a news switch statement so that for example the average temperature this week was < 10 it would give a message such as "it was a cold week". Here is my code and what I am doing wrong:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TempAverages
    public partial class Form1 : Form
        public Form1()

        private void btnCalc_Click(object sender, EventArgs e)
            int tempMonday = Convert.ToInt32(txtMonday.Text);
            int tempTuesday = Convert.ToInt32(txtTuesday.Text);
            int tempWednesday = Convert.ToInt32(txtWednesday.Text);
            int tempThursday = Convert.ToInt32(txtThursday.Text);
            int tempFriday = Convert.ToInt32(txtFriday.Text);
            int weekdays = 5;
            int tempAverage = (tempMonday + tempTuesday + tempWednesday + tempThursday + tempFriday) / weekdays;

            switch (weathernews)

                case 1: tempAverage < 10;
                    lblResult.Text = "it was a cold week with only" + tempAverage;

                case 2: tempAverage > 20;
                    lblResult.Text = "it was quite warm with" + tempAverage;



i get error messages such as "the name weathernews does not exist in the current context"

4 Years
Discussion Span
Last Post by ddanbe

Indeed, weathernews is nowhere defined in your code. In this case(No pun intended) you are better off with an if elsif statement I guess. Happy programming!

double tempAverage = 8; // just suppose
            string str = string.Empty;
            if (tempAverage < 10)
                str = "it was a cold week with only" + tempAverage;
            else if (tempAverage > 20)
                str = "it was quite warm with" + tempAverage;
            // fill the text of your textbox with str

Something like the above?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.