Sunday, July 26, 2009

Help with c++?

I've no experience in programming, It just happen happen that we had a computer class and we are using C++. by the way I'm using the borland turbo c++ v1.01





This program below is a sample program I found in the Internet. When I enter this program it says "unable to open include file STDIO.H". Is there something wrong with this program? Help me please





#include %26lt;stdio.h%26gt;


main () {


int i,n,sum;


scanf("%d",%26amp;n);


sum=0;


i=1;


while (i%26lt;=n) {


sum = sum + i;


i++;


}


printf("%d",sum);


}

Help with c++?
Looks like C code instead of C++, judging by the way the main function is declared without a return type. Not sure if it has anything to do with stdio.h though. Most c++ compilers come with it.





The C++ version would probably look like:





#include %26lt;iostream%26gt;


int main()


{


int n, sum=0;


std::cin %26gt;%26gt; n;


for(int i = 1; i%26lt;=n; i++)


{


sum+=i;


}


std::cout %26lt;%26lt; sum;


return 0;


}
Reply:Looks like c code. Try Dev-C++. The compiler that your computer is using probably doesn't recognize studio.h. I suggest dev-c++, the compiler is a lot better.


You can download it from the internet for free.


cheers!!!
Reply:Your compiler has not been installed correctly or you have changed where the compiler looks for its #include files.


Try reinstalling Turbo C++, that will fix where it searches for files #included.





Dazza


No comments:

Post a Comment