How to convert from Codeblocks to Visual Express?

I got this working in Codeblocks, but I only recently figured out how to start up MS Visual express 2010. How would I get this conversion program to work?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//  F2C Fahrenheit to Celsius
#include<iostream>
#include<assert.h>

 using namespace std;

int main()
{

    char input;// input for f or c
    int num;// the furture input for the value to convert from

    while ((input >=-273) && (input !='q') && (input !='Q'))//loops program
    {

    cout << "Enter what you wish to convert from Celsius or Fahernheit[C/F]:  ";
    cin >> input;//get the c or f
    cout << "You Entered: " << input ;

    if(input == 'c' || input == 'C')// if the input is c
    //convert c to f

        {
        cout << "\nEnter C: ";
        cin >> num;// get the c
        cout << "\nThe Fahrenheit is: "<< num*1.8 +32 << endl;//output the f

        }

        else if(input == 'f' || input == 'F')

        {
      //convert f to c
        cout << "\nEnter F: ";
        cin >> num;//get the f
        cout << "\nThe Celsius is: "<< (num-32) /1.8 << endl;//output the c
        }
        else if(input =='q' || input =='Q')//ends program
            break;
        else
    {
      //the value was not c or f so give error
      cout << "\nYou didn't enter c or f" << endl;
    }


}

      return 0;
}
What is the problem?

Both CB and VS are IDE, integrated development environments. That is mostly GUI and not really language dependent. Each has to be told differently, which source files belong to "a project". Project defines which files to compile and with what options, when you press a "Compile" button.

Under the hood each has a C++ compiler, which they call to compile C++ sources into binary. The only reason for the compilation to fail with different compiler is when the source uses features that are not supported by the second compiler.
Theoretically they should act the same, then?
But when I run it in Codeblocks, it works.

However, in Visual, its saying 'input' isn't initialized. but I have it in
char input;// input for f or c
int num;// the furture input for the value to convert from

while ((input >=-273) && (input !='q') && (input !='Q'))//loops program
You do not give input a value before the while loop.

VS has picked up this error. Maybe code::blocks wasn't configured to pick up this error.

The program works because input will be some random value when the program starts.

This value will be always >-273 and is only by slim chance to be 'q' or 'Q' so the while loop can execute most of the time.


Topic archived. No new replies allowed.