dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Need Help w/While Loop & Switch

  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Red face Need Help w/While Loop & Switch

    Hi All,

    This is my first post here as I am just starting to teach mself programming. I am trying to write a simple program that changes Fahrenheit to Celcius and vice-versa.

    I am having trouble with the loop, I can't seem to get out of it even once a selection has been made. As I am totally new to this, I may be going about it the wrong way but I have posted the code below. I am using the Dev-C++ IDE. All help greatly appreciated and any explanation to what I have done wrong would be really helpful too. Thank you in advance.

    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
    SetConsoleTitle("Tester");

    int blank;
    float Temperature;
    char Conversion;

    cout << "Enter Temperature: \t";
    cin >> Temperature;




    while (Temperature
    {
    cout << "Convert to Celcius or Fahrenheit <C/F>:";
    cin >> Conversion;

    switch (Conversion)
    {//start switch

    case 'C':
    case 'c':{
    cout << "Temperature is equal to " << (((Temperature - 32) * 5) / 9);
    break;
    }


    case 'F':
    case 'f':{
    cout << "Temperature is equal to " << (((9 * Temperature)/ 5) + 32);
    break;
    }


    default:{
    cout << "INVALID";
    }

    }//end switch

    }//end while
    return 0;
    }

  2. #2
    Join Date
    Aug 2002
    Posts
    879

    Re: Need Help w/While Loop & Switch

    1. I have no idea why you are using a while loop.
    2. How a while loop works, here you will see why your while loop will never end!
    http://www.java2s.com/Tutorial/Cpp/0...gwithwhile.htm
    3. First C++ Steps tutorials
    http://www.cplusplus.com/doc/tutorial/

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)