2 Replies - 332 Views - Last Post: 19 November 2012 - 09:42 AM Rate Topic: -----

#1 generic_user_1234  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 18-January 12

If/else if problems

Posted 18 November 2012 - 08:56 PM

Hi, i am supposed to make a program that shoots out a appropriate answer to when a value has been added. I am having troubles with this, everytime i try to run the program, it does run, but what happens is that, the same word "freezing" comes up. I cant seem to figure this out. My code is fairly simple! Please if someone could help me out, it would sooo great!! Thank you.
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 assign4Part1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int tempInteger=0;
            
            if (tempInteger <= 32)
            {
                label2.Text = "Freezing";
               
            }
            else if (tempInteger > 80)
            {
                label2.Text = "Hot";
                label2.Focus();
                label2.Select();
            }
           
        }
    }
}


This post has been edited by macosxnerd101: 18 November 2012 - 09:56 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: If/else if problems

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: If/else if problems

Posted 18 November 2012 - 09:04 PM

That is probably because you have set your tempInteger value to 0 and since it is less than 32, the "freezing" text is displayed.

You may want the user to input his desired temperature and if it is more than 32, then you are bound to get "Hot" as the text.

regards,
Raghav
Was This Post Helpful? 4
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5632
  • View blog
  • Posts: 12,085
  • Joined: 02-June 10

Re: If/else if problems

Posted 19 November 2012 - 09:42 AM

*
POPULAR

View Postgeneric_user_1234, on 18 November 2012 - 09:56 PM, said:

I cant seem to figure this out.

            int tempInteger=0;
            
            if (tempInteger <= 32)
            {
                label2.Text = "Freezing";
               
            }



While raghav as pointed out the issue I just had to say something.

You really couldn't figure it out? I often recommend reading code out loud. It might sound silly, but it works.

Read this OUT LOUD:

Quote

Integer tempinteger equals 0.
If tempinteger is less than 32, the lable text equals "freezing"

I want to believe that if you hear that then the logic of why this is happening would become very clear.

If not, then I urge you to schedule a face-to-face with your professor and ask him about getting some extra tutoring before you fall further behind.
Was This Post Helpful? 5
  • +
  • -

Page 1 of 1