views:

286

answers:

2

Hi

I am creating a simple C++ program to ask user for fahrenheit in main thread and then convert this value to Celsius in another thread.

But i continue to get one error . This error keeps

visual studio 2008\projects\cs1\cs1\cs1.cpp(16) : error C2143: syntax error : missing ';' before '='

This problem sometimes disappears but instead of that a run time exception appears. I am using Visual studio 2008, windows XP.

thanks -Sunny Jain

#include "stdafx.h"
#include "stdafx.h"
#include "windows.h"
#include "stdlib.h"
#include "stdio.h"
#include "process.h"
#include "conio.h"
#include "iostream"
using namespace std;

bool flag= false;

void calculateTemperature_DegreeCelcius(void * Fahrenheit)
{
    float far;
    far=*((float*) Fahrenheit);
    float celcius = (5.0/9.0)*(far - 32);
    cout << "\nDegree Celcius :";
    cout << celcius;  
    flag = true;
}


int _tmain(int argc, _TCHAR* argv[])
{
    float temp_Fahrenheit;

    while(true){
     cout << "\nEnter Degree Fahrenheit value you want to convert to Degree Celcius\n";
     cout << "Degree Fahrenheit :";    
     cin >> temp_Fahrenheit;
     _beginthread(calculateTemperature_DegreeCelcius, 0, &temp_Fahrenheit);
 while(true){
  if(flag==false){
   Sleep(200);
  } else {
   break;
  }
 }

 char *command = (char *)NULL;
 cout<< "\nDo you want to continue ? yes/no :";
 cin>> command;

 if (strcmp("yes",command)){
  flag = false;
 } else {
  break;
 }
    }
    return 0;
}
+12  A: 

In many C/C++ compilers, especially Microsoft ones, far is a reserved word (either keyword or defined in a header).

plinth
To explain a little more: far cannot be used as a variable name, because it has special meaning. Just like you can't name a variable "for" or "if". Change the variable name to something else. I personally would choose degF.
abelenky
Here is a list of Visual C++ Keywords and far is not listed: http://msdn.microsoft.com/en-us/library/2e6a4at9.aspx
Justin
+6  A: 

far is a #define in WinDef.h

#define far
#define near
#if (!defined(_MAC)) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
#define pascal __stdcall
#else
#define pascal
#endif
M1EK