Posted: Tue Mar 17, 2009 4:15 am Post subject: A problem about the c++ programming.
c++:
#include <iostream.h> #include <cstdlib.h> int main() { char ans;
do { int fav=rand()%32;
int num;
do {
cout<<"Guess my secret number(0-32) ";
cin>>num;
cout<<(num<fav?"Too Low":num>fav?"Too High":"Right")<<endl;
} while(num!=fav);
cout<<""Go Again?(y/n)";
cin>>ans;
}
while(ans==y);
return 0;
}
code:
ERROR:fatal error C1083: Cannot open include file: 'cstdlib.h': No such file or directory
Thank you for solving my question....
[b]Mod Edit: Remember to use syntax and code tags! Thanks
code:
[syntax="cpp"]Code Here[/syntax]
[b]
Sponsor Sponsor
michaelp
Posted: Tue Mar 17, 2009 8:25 am Post subject: RE:A problem about the c++ programming.
Use code tags!
And it should be #include <cstdlib> and #include <iostream>. iostream.h is not standard( I think ) and standard C headers that are used in C++ drop the .h extension, and add a c in front.
Example:
stdio.h
becomes
cstdio.
Tony
Posted: Tue Mar 17, 2009 11:43 am Post subject: RE:A problem about the c++ programming.
@CHINA_yanglei -- don't mix C with C++, and you'll be avoiding many problems.
Posted: Tue Mar 17, 2009 8:34 pm Post subject: Re: RE:A problem about the c++ programming.
michaelp @ 17/3/2009 wrote:
Use code tags!
And it should be #include <cstdlib> and #include <iostream>. iostream.h is not standard( I think ) and standard C headers that are used in C++ drop the .h extension, and add a c in front.
Example:
stdio.h
becomes
cstdio.
I also find a error about the "y" which is not appended ' ',and I correct my code just like your advice.The result is satisfied.Thank for your suggestion.Good luck to you!