-
C++ Help
Whats wrong with this code?
#include <stdlib.h>
#include <conio.h>
#include <iostream>
using namespace std;
*/
int main()
do
{
cout << "Still in the do...while loop" << endl;
} while (!kbhit());
return EXIT SUCCESS
}
The error message is:
Line 5: parse error before '/'
Any Suggestions?
-
#include <stdlib.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main(){
do
{
cout << "Still in the do...while loop" << endl;
} while (!kbhit());
return 0
}
-
Shmoo, I looked over the code for the hello world program you showed us in the irc. Here is what my version looks like.
#include <iostream.h>
int main()
{
cout << "Hello World!";
return(0);
}
-
You ended a comment without starting one, */ should be placed after a comment with /* before it.
-
You can technically use all the */'s you want in your code without an adverse effects...:) Just thought I would comment on that...:)
-
#include <stdlib.h>
#include <conio.h>
#include <iostream>
using namespace std;
*/
int main()
do
{
cout << "Still in the do...while loop" << endl;
} while (!kbhit());
return EXIT SUCCESS
}
Well Shmoo I get 7 errors with this code, so obivious stuff your doing wrong
1) <iostream> should be <iostream.h>
2) */ needs a closing comment */
3) your do statement is all messed up
4) wtf is (!kbhit()); I've never seen that in my life
5)if your going to use <conio.h> make sure you use getch(); to or else you defeat it's purpose
6)Learn how to do a while loop and execute conditions
here is an example, this program doesn't need that **** use void main () and get rid of it
If you need more help let me know
#include <iostream.h>
void main()
{
int x = 1;
while( x = 1)// put your loop condition in here
{
cout << "Still in the do...while loop";
}
}
Yes this is a never ending loop..
-
remove all .h in header files and remove the */
about the */ why have you used it ??
freeon:
kbhit() is a function that allows a process to happen while the user presses a key
it's in conio.h so he's right
-
I never heard that **** before, but it's good to know
-
<iostream> should be <iostream.h> isn't exactly correct. <iostream.h> is deprecated in favor of using namespaces. instead of doing:
using namespace std...
why don't you just do
using std::cout;
using std::cin;
using std::endl;
In other words, only call the objects from the namespace you absolutely need. The whole
reason <iostream.h> is deprecated is so you can use the namespace in this manner. Any
decent optimizing compiler should strip out unneeded objects anyway, but this enforces that
for any compiler that doesn't. Just thought I would mention this.
Happy Hacking
-
I have noticed that there is a curly bracket missing between the int main() and do...
you actually have it as
#include ..... blah blah
int main()
do
{
....
}
}
it should be
...
int main()
{
do
{
...
}
}
the indents are not necesary, but it makes it clearer to me for reading. I don't know about the kbhit() function... I have never seen it b4 either... but that does not mean it does not exist