-
Help on a code problem
Well, i got this when i try to compile this piece of code:
Code:
#include <stdio.h>
void main()
{
int first,second;
printf("please enter the first number: ");
scanf("%d", &first);
printf("please enter the second number: ");
scanf("%d", &second);
printf("The sum of the numbers is %d\n",
first+second);
}
I currently use Dev-CPP, and i tryed it on a friend's Visual C++, almost same results.
P:S
What is the best IDE and compiler to use for learning C? (Cost is unimportant)
-
What exactly is the problem
except void main instead of int main()
this code has no problems.
-
N/A
The problem is that after i put in the second number, the program just closes itself.
Without showing the output.
Also, do you think Visual C++ 6.0 is suitable for beginner's learning?
-
Add #include <stdlib.h>
and just before return 0; add a system("PAUSE");
-
system is not so portable...
you can read FAQ http://faq.cprogramming.com/cgi-bin/...&id=1043284385
In my opinion - VC6 is goog enough, maybe a little bit old and not fully standard compliant.
You can look at the VC 2005 Express that is free, more standard compliant and should inherit all the good features of the VC6... i cannot be sure on the last statement because I'm still using mostly the VC6
-
-
I would put money that you didn't save the file as .c and you have it on default .cpp *c++ file*. Thats why it wont work. Also use Dev C++ IDE on bloodshed.net, I have been using it for a while and find it to be to quality but then again after ANSI C was produced and such standard was set. All compliers that say there ANSI supported then will all run the same way, thus its the setting on the IDE and the apearence of the IDE you should look for. Find what you work best with. Back to your code, why did you void main()? Sounds like overkill.
-
Well, i managed to get it to work on Visual C++, due to the help of Vart and Arminel(Thanks :) )
But on Dev-C++ i still keep getting this error(View the Screenshot above). But i guess that's already a problem with the Dev-C++ client, anyway, thanks again for the quick help.
-
There is no void main. It should be int main. Always.
Also, instead of system("PAUSE"), which is non-portable, I would use getchar(), which is portable.
-
I complied this with ease in Dev C++ ver 4.9.9.2. Maybe you have not have it set in C. Try saving it as a .C file then try. I cant see you error I am at school so I am just guessing.
-
It's ok, i have bought Visual C++. :)