Why even bother with cin >> s ...
Is it April 1st? Or is this a submission to the Annals of Bad Programming?
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
[B]hi there....ur program is working fine
harshchandra
Junior Poster in Training
68 posts since Nov 2004
Reputation Points: 7
Solved Threads: 1
This actually compiles and runs too. I can't tell you way.
Had to move the macro(?) out or get the same results as the originator.
[php]
// teasing Dev C++
#include
#include
#define PRODUKT(N,M,VARIABLE) \
{ \
VARIABLE = N; \
for (unsigned int i = N + 1; i <= M; ++i) \
VARIABLE *= i; \
}
using namespace std;
int main()
{
char s;
unsigned int ergebnis;
PRODUKT(3,5,ergebnis);
cout << ergebnis << endl;
PRODUKT(3,9,ergebnis);
cout << ergebnis << endl;
system("PAUSE");
//cin >> s;
return 0;
}
[/php]
I wish you would post the original code for Wayne at the Dev-C++ forum:
http://sourceforge.net/forum/forum.php?forum_id=48211
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
it might have been confusion of namespaces? surely should be for namespace std. and vega is right too, that macro needed to be global. only #ifdef / #ifndef / #endif can be in executable statement blocks (i think anyway, there may be others). For example
if(x == 1)
#define message "x equals 1"
else
#define message "x does not equal 1"
will cause all sorts of problems as they are PREPROCESSOR directives -> ie these get processed before compilation and dont affect the running of the program.
I got out the old Deitel from the college days and looked up the rules for a MACRO. Whatever it expands to, if it looks right it is right! No wonder the old prof hated them, it was a way the huns could get even with him.
If you follow the vexing include trail of the iostream header, you will eventually find out that it actually uses stdio.h!!!
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
so
#include <iostream>
#include <cstdio>
is equivalent to just including iostream? i beg to differ. Ive included iostream before and still needed to include stdio for some functions, unless it was another error....
I am saying stdio.h, not cstdio, is in iostream in a convoluted way. Just bring it up in your editor and follow the yellow brick road through the includes. If you hum the tune along with the search it might help.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417