URGENT-computer doesn't recognize Leonardo

Hello everyone.. i have a problem with Arduino leonardo (the same problem happened with two devices) that the computer doesn't recognize the Leonardo any more. Here, how it occurs: i installed the IDE and the Drivers, the computer recognized the device very well. Then i wrote a simple program to print /* My name is moumen /, i got the result in the serial monitor, every thing run perfectly.

void setup() 
{
Serial.begin(9600);

}

void loop() 
{
Serial.println("i'm moumen");
}

I pressed the reset button but the program was still running !! unplugged the USB then plugged it in again, it was still running the same program. It didn't vanish!! shouldn't it be deleted ? i just opened an empty sketch and uploaded to delete the last one. Till here the problem didn't occur. Once i tried to right a new program by creating a new function as you can see below (Just for testing the code)

int main()
{
int result = 5*9;
return result;
}


void setup() 
{
Serial.begin(9600);

}

void loop() 
{
Serial.println("i'm moumen");
Serial.println(main());

}

after verifying and compiling without any errors i uploaded it. Once the sketch had been uploaded i didn't get any results (outputs). i pressed the reset button, unplugged the USB cable then plugged it again, the arduino leonardo COM port disappeared from Tools->Ports and the computer didn't recognize the device any more but in the same time the green LED is turning on and the L LED (orange) is also turnning on. i tried to configure the driver from the device manager but still the same problem. On the other hand, when i press the reset button the Arduino Leonardo bootloader COMxx appears for few seconds then disappears again!! i tested every component in the board but nothing burned. As i mentioned before this problem happened with two devices. I bought the first one before one week and had this problem (but with other sketches). The second one i got it today and had exactly the same problem. i tried with several computers and USB cables but still the same.

for the information i'm using windows 7 professional service pack 1 64bit

thanks..

Moumen: I pressed the reset button but the program was still running!! unplugged the USB then plugged it [in] again. It was [still running] the same program. It didn't vanish!! Shouldn't [it] be deleted?[/quote] No, it should not be deleted. The Arduino runs the last sketch uploaded when you provide power or reset. It wouldn't be of much use if it forgot your sketch every time you disconnected power.

you got a point over there, but do you have any idea what’s going with my devices !!

Try naming your new function something other than "main()". I suspect it is conflicting with the main() function defined in the Arduino core. If that is the case your Arduino is executing main() once and then waiting for you to upload a new sketch. Since main() doesn't do Serial.begin() you don't get a Serial connection.

The main() in the Arduino core is the function that calls setup() once and then calls loop() repeatedly. If you replace it then your setup() and loop() will not be called automatically.

good to know.. thanks for support i solve the USB problem by these following steps :

open your IDE,in the empty sketch press upload, press the reset button (while it uploading) open the device manager and reset your arduino. Try to memorize the bootloader COM port (It will appear for few seconds only) go to your IDE->File->Preferences open the preferences txt file, you will find it in the directory shape. change serial.port.file & serial.port to the COM port you saw in the device manager. close the file and return to the IDE. repeat the first step again. It worked for me with two devices :)