# Beginner Question

• 01-23-2007
Chobo
Beginner Question
How do I fix this? I don't know how to convert inputted choice to equal the If statement.

Code:

```#include "stdafx.h" #using <mscorlib.dll> using namespace System; int _tmain() {         double cont = 1, r, theta, x, y, A, B;     __wchar_t choice;         while (cont == 1)         {           Console::Write( S"A        Convert Polar Coordinates to Cartesian \n");         Console::Write( S"B        Convert Cartesian Coordinates to Polar \n");         Console::Write( S"C        Determine Roots of a quadratic equation \n");         choice = Char::Parse(Console::ReadLine());   if ( choice == A)   {     Console::Write( S"R: ");     r = Int32::Parse( Console::ReadLine());         Console::WriteLine( S"Theta: ");         theta = Int32::Parse( Console::ReadLine() );         x = r * Math::Cos(theta);         y = r * Math::Sin(theta);         Console::Write( S"X: {0}", x.ToString());         Console::Write( S"Y: {0}", y.ToString());         return 0;   }   if ( choice == B)   {     Console::WriteLine( S"X: ");         x = Int32::Parse( Console::ReadLine() );         Console::WriteLine( S"Y: ");         y = Int32::Parse( Console::ReadLine() );         r = Math::Sqrt(Math::Pow(x, 2)+Math::Pow(y, 2));         theta = Math::Atan(y/x); return 0;   }         } }```
• 01-23-2007
manutd
Methinks this is C#. This is a C++ forum. Mods, please move.
• 01-23-2007
Chobo
This is C++ with .net
• 01-23-2007
swoopy
Code:

```  if ( choice == __wchar_t('A')) . .   elseif ( choice == __wchar_t('B'))```
• 01-23-2007
manutd
Oh, OK. My fault, I haven't used .NET in so long.
• 01-23-2007
Chobo
Quote:

Originally Posted by swoopy
Code:

```  if ( choice == __wchar_t('A')) . .   elseif ( choice == __wchar_t('B'))```

Thanks for the help but, inputting A still doesn't bring up thing.
• 01-23-2007
Chobo
Nevermind it works. Thanks!
• 01-23-2007
Chobo
What does it mean when it says unreferenced local variable, (A and B)?
• 01-23-2007
CodeMonkey
It means you didn't "use" A or B.
Code:

```  double cont = 1, r, theta, x, y, A, B;     __wchar_t choice;         while (cont == 1)         {         Console::Write( S"A    Convert Polar Coordinates to Cartesian \n");         Console::Write( S"B    Convert Cartesian Coordinates to Polar \n");         Console::Write( S"C    Determine Roots of a quadratic equation \n");         choice = Char::Parse(Console::ReadLine());   if ( choice == A)```
Maybe the compiler is warning you of this undefined behavior. Technically, the variable is referenced by the == operator, no? I don't know. Initialize your variables.
• 01-23-2007
Chobo
Hi, thanks for all the answers.. one more question

Code:

```  if ( choice == __wchar_t('A'))   {     Console::Write( S"R: ");         r = Double::Parse( Console::ReadLine());         Console::Write( S"Degrees: ");         degree = Double::Parse( Console::ReadLine() );         rad = degree  * (Math::PI/180);         Console::WriteLine("");         x = r * Math::Cos(rad);         y = r * Math::Sin(rad);         Console::WriteLine( S"X: {0}", x.ToString());         Console::WriteLine( S"Y: {0}", y.ToString());   }```
Do you guys see anything wrong with this?
It seems to work fine until X or Y is suppose to equal 0.. it gives some e-16 value.
• 01-23-2007
CodeMonkey
Hm. Your trig funtions are either returning terribly small numbers, or you're having floating point issues. To debug, every time a double is assigned, print out its value right afterwards to make sure things are what you expect them to be.
• 01-23-2007
Chobo
Everything is fine until:

Code:

```        x = r * Math::Cos(rad); y = r * Math::Sin(rad);```
Where it works except when rad is say PI..
• 01-23-2007
Chobo
How do you cut off a Double variable after say 2 digits?
• 01-23-2007
swoopy
>How do you cut off a Double variable after say 2 digits?
In standard C++, you can do this:
Code:

```#include <iostream> #include <iomanip> int main() {   double num = 5.12345;   std::cout << std::setprecision(2) << std::fixed << num << '\n'; }```
I have no idea how to do it in .NET.

Also just so you know:
Code:

`  if ( choice == __wchar_t('A'))`
I'm not positive, but I believe you can write this as:
Code:

`  if ( choice == T('A'))`