CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2008
    Posts
    2

    Can't figure out

    I can not figure out what it is wrong with this program. It is supposed to ask user to enter a number and then convert the number (from fahrenheit) to celsius. Both input number and result supposed to be entered and displayed on the text box.

    any idea why is not workin?

    Please see attachment.

    thanks.
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Can't figure out

    Quote Originally Posted by rturus
    I can not figure out what it is wrong with this program. It is supposed to ask user to enter a number and then convert the number (from fahrenheit) to celsius. Both input number and result supposed to be entered and displayed on the text box.

    any idea why is not workin?

    Please see attachment.

    thanks.
    What happens when you step through each line with the debugger?

    Which line performs an action other than what you would expect?
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Oct 2008
    Posts
    2

    Re: Can't figure out

    Actually it is OK until the number would be displayed on the second text box. It does ask user to enter the fahrenheit in the first tex box but when second box pops up nothing is there.

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Can't figure out

    Quote Originally Posted by rturus
    Actually it is OK until the number would be displayed on the second text box. It does ask user to enter the fahrenheit in the first tex box but when second box pops up nothing is there.
    The code you posted is a CONSOLE application, there is no such as a "Text box" in a console application.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Lightbulb Re: Can't figure out

    try this:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    namespace FtoC
    {
        class Program
        {
            static void Main(string[] args)
            {
                int fah;
                double cent;
                //input
                Console.Write("enter temp in fah >");
                fah = int.Parse(Console.ReadLine());
    
                //process
                cent = (double)(fah - 32) * 5 / 9;
                //output
                Console.Write("the result in cent is {0}", cent);
                Console.ReadLine();
    
            }
        }
    }
    also i removed using System.Linq; from your code because it is not necessary.

    Touraj Ebrahimi [toraj_e] [at] [yahoo] [dot] [com]
    Last edited by toraj58; October 19th, 2008 at 03:15 AM. Reason: mistake in type

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Can't figure out

    Quote Originally Posted by toraj58
    try this:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    namespace FtoC
    {
        class Program
        {
            static void Main(string[] args)
            {
                int fah;
                double cent;
                //input
                Console.Write("enter temp in fah >");
                fah = int.Parse(Console.ReadLine());
    
                //process
                cent = (double)(fah - 32) * 5 / 9;
                //output
                Console.Write("the result in cent is {0}", cent);
                Console.ReadLine();
    
            }
        }
    }
    also i removed using System.Linq; from your code because it is not necessary.

    Touraj Ebrahimi [toraj_e] [at] [yahoo] [dot] [com]

    Good, except for the last "Console.ReadLine()".A console program is supposed to exit immediately upon competing its task.

    If you are developing a console application where you need to see the output, you should run it from a console window, and NOT have something that artifically pauses the execution.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Can't figure out

    yes, you are right; thanks for your hint.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured