I have Errors and warnings with Code::blocks. On MS VC++ 2005 EE everything's fine.
Im not good at speaking English...
-------------- Build: Debug in Timer ---------------
Compiling: main.cpp
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings
I Use on Windows Code::Blocks with the newest nightly build. My Compiler ist MinGW Version 5.1.3. I used a console aplication.
-------------- Build: Debug in Timer ---------------
mingw32-g++.exe -Wall -fexceptions -g -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings
My Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int Auswahl;
int Zeit;
do
{
cout << "1 für Sekunden" << endl;
cout << "2 für Minuten" << endl;
cout << "3 Hilfe" << endl;
cout << "4 um zu Beenden" << endl;
cin >> Auswahl;
cout << endl;
switch (Auswahl)
{
case (1):
{
cout << "Gib die Zeit in Sekunden ein: ";
cin >> Zeit;
for (Zeit; Zeit > 1; Zeit--)
{
cout << "Noch " << Zeit << " Sekunden" << endl;
Sleep (1000);
}
if (Zeit == 1)
cout << "Noch " << Zeit << " Sekunde" << endl;
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
cout << "Zeit ist abgelaufen" << endl << endl;
} break;
case (2):
{
cout << "Gib die Zeit in Minuten ein: ";
cin >> Zeit;
if (Zeit > 1)
{
for (Zeit; Zeit >= 1; Zeit--)
{
cout << "Noch " << Zeit << " Minuten" << endl;
Sleep (60000);
}
}
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
cout << "Zeit ist abgelaufen" << endl << endl;
} break;
case (3):
{
cout << "Das ist ein Programm, der die Zeit bis zum Ablaufen der Zeit zählt. Wenn die Zeit abgelaufen ist benachrichtigt das Programm sie mit einem Ton." << endl;
cout << endl;
} break;
default:
cout << "Falsche Eingabe!" << endl;
}
} while (Auswahl != 4);
return 0;
}
I Use on Windows Code::Blocks RC2 with the newest nightly build. My Compiler ist MinGW Version 5.1.3. I used a console aplication.
-------------- Build: Debug in Timer ---------------
mingw32-g++.exe -Wall -fexceptions -g -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings
My Code:
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
Hi,
remove "L" from all strings in PlaySound (...) calls.
P.S. Also I think that code
for (Zeit; Zeit > 1; Zeit--)
{
}
should be something like that
for (int counter = Zeit; counter > 1; counter--)
{
cout << counter;
}
Thanks.
-------------- Build: Debug in Timer ---------------
mingw32-g++.exe -Wall -fexceptions -g -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\Timer.exe obj\Debug\main.o
obj\Debug\main.o: In function `main':
C:/C++/Timer/main.cpp:32: undefined reference to `PlaySoundA@12'
C:/C++/Timer/main.cpp:56: undefined reference to `PlaySoundA@12'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings
Do you know what's wrong here?
I removed the L and I changend the fors to
for (int i = Zeit; i > 1; i--)
Is it standard to initialize the variables in the loops?