0

this simple program isnt working why plz help
#include <stdio.h>
void main()
{
int x=0;
printf("%d",x);}

0

>isnt working
"Isn't working" doesn't work. Be more specific. Does it fail to compile? If so, what compilation errors do you get? Does it fail to run? If so, what errors do you get? Is the output wrong? If so, how?

My guess is that the window pops up, prints the output, and then closes before you can read it. In that case, change your code like so:

#include <stdio.h>

int main()
{
  int x=0;
  printf("%d",x);
  getchar();
}
0

ok it worked just one question alwayz i write int main()= just like void main()
and getchar() = just like return (0) ?is it alwayz i have write it down or its optional

0

Getchar is optional, it means that you have to press a key to continue.
Always use return 0 in your main() Narue just forgot it this time.

int main is NOT optional! void main is very bad coding habit!

Edited by Nick Evan: n/a

0

and yea in this program there is for loop and while loop and arrays ... just like turbo c++ or its totally different? thx in advance

0

>alwayz i write int main()= just like void main()
Yes. void main() is wrong, int main() is right.

>getchar() = just like return (0) ?
No. getchar is a separate entity entirely. The reason I didn't put in a return statement is because C++ allows you to omit it and 0 will be returned automatically when you fall off the end of main. getchar simply pauses for input so that the window isn't destroyed when the program ends. If you feel better returning 0 explicitly, you can do so:

#include <iostream>

int main()
{
  std::cout<<"Hello, world!\n";
  std::cin.get();
  return 0;
}
0

ok THX AND THX THX i new that this website contains good peaple thx but for the last question

0

>in this program there is for loop and while loop and
>arrays... just like turbo c++ or its totally different?
You're still programming in C++, the fundamentals aren't going to change drastically. The big difference will be in the library features you use because I'm reasonably sure you've been using pre-standard C++, and the library has grown and improved since the language was standardized in 1998. I recommend you get a book written after 2000 for a description of the current language.

0

man its very difficult for me cz in my college we are now learning the old fashion way of programing i have to stick with them for the mean time and after that we will progress for this program it didnt work what to do?
#include <stdio.h>
int main()
{ int x=0,i;
for(i=0;i>5;i++)
{
scanf("%d",&x);
x=x+5;
printf("%d",x);
}getchar();}

0

>it didnt work what to do?
If you keep saying "it doesn't work", I'll stop helping you. Explain in detail how it doesn't work and I'll tell you why it doesn't work. I may even tell you how to fix it. But my knee jerk reaction to "it doesn't work" is "bummer".

Also, your code is awful. Learn how to format it properly and then use code tags when you post it here. Furthermore, if you're going to write C, you might as well just go with full blown C instead of some bastardization of C and C++.

>for(i=0;i>5;i++)
i will never be greater than 5 if you initialize it to 0. Your loop does nothing.

0

I DIDNT ASK FOR UR OPINION !!!!!!!

You're going to get it sometimes whether you like it or not. So get over it. We're all one big happy family here and do not like people with a lousy or smart-mouthed attitude. You are most welcomed to join in if you drop your greater-than-thou attitude.

I wasn't trying to be rude -- just asking you not to use abbreviations like that here because most people won't know what they are.

0

if its true what are u are saying then ull accept any guest am i right lol dont try me in thez situations lol i am very caution in talking and in listening to others anyway well here it is ur welcomed as well see ya i have to go now

0

thx and with the help of our GOD we will alwayz be polite see ya ps:i really liked this webiste i must tell my other friend join in("_")

0

I DIDNT ASK FOR UR OPINION !!!!!!! and why i said i dont care because its true i dont care about someone is annoying me lol see ya

actually you did, by posting here

and many C++ compilers run in vista (i have VC5 running even (dont ask why, long story) - it works fine after some tinkering with the installer)

0

well thx every one for helping me out and im going to study well how to write programs by my own because im going to enter engineering of electricity power maybe or comm whatever and if i had any other problem ill try to solve it if i cant ill ask for prof see ya everyone nice to meet u (*_")

0

Hello tarekkkkk and everybody else of course :D
<<----------------

tarekkkkk:
plz help and yes submit a direct link if u can and thx for advance plz hurry up i have assignment next week i have to finish it lol
.....
OK i dont care what is ur problem with my writing all i need is c++ program i recently tried to download visual c++ and turbo c++ .... and many didnt worked on vista i dont know any other solution except asking prof about my issue lol is this hard on u

Other people can help u fast, ONLY when they are provided with a clear description from your side. I think that u should consider using commas and fullstops when u write your posts. Otherwise nobody is going to understand u easily and thus help u. Especially if u right yalla yalla (fast in arabic)

Narue:
i r nt knowing wut t3h hell ur talkng abt lol rofl jejeje!!!!!111
....
Then why do you keep replying with increasing irritation?

Correct me if I am wrong but sometimes I think u enjoy "provoking" the CHAOS.... :D :D :D
---------------->>

Narue:You're still programming in C++, the fundamentals aren't going to change drastically. The big difference will be in the library features you use because I'm reasonably sure you've been using pre-standard C++, and the library has grown and improved since the language was standardized in 1998. I recommend you get a book written after 2000 for a description of the current language.

Tarekkkk: man its very difficult for me cz in my college we are now learning the old fashion way of programing i have to stick with them for the mean time and after that we will progress for this program it didnt work what to do?

Narue is 100% right u should consider buying a new book (preferably after 2005 in my opinion). This way u will learn to use the STANDARD C++ which will compile in any compiler and no matter the operating system.-> This way u will be able to create a more "portable" code.

Some examples in your code of non-standard c++ are:

scanf("%d",&x);
....
printf("%d",x);

which are rather features of C.
In addition, u might consider using eclipse as IDE for developing your code which is free.
Here is a tutorial concerning its installation and configuration:
http://sherifabdou.com/2008/06/eclipse-cdt-c-cpp-on-windows-vista/

0

>Some examples in your code of non-standard c++ are:
><snip code>
>which are rather features of C.
That's not quite correct. printf and scanf are both standard C++, despite what the purists would have you believe. By pre-standard, I mean stuff like this:

#include <iostream.h> // Not standard!
0

>Some examples in your code of non-standard c++ are:
><snip code>
>which are rather features of C.
That's not quite correct. printf and scanf are both standard C++, despite what the purists would have you believe. By pre-standard, I mean stuff like this:

#include <iostream.h> // Not standard!

In this page:

http://www.cplusplus.com/reference/

we can read:

...
For more info see the reference page for the C++ Input/Output Library.

C Library
The elements of the C language library are also included as a subset of the C++ Standard library. These cover many aspects, from general utility functions and macros to input/output functions and dynamic memory management functions.
They are divided in several files. Our reference at this moment covers the following header files of the C library:
...

The way I see it (my personal opinion) is that they included these C libraries in the C++ only to make the TRANSITION for all those C programmers easier, because in the past C was the dominating language in comparison to C++ and they didnt want the programming community to refuse migrating to c++....

Nevertheless I prefer and try to use C++ characteristics.

Finally if u think there is no big deal then u might consider as moderator.... to merge the C++ and C forums in one forum in this site since all these C libraries were included in the C++ standard :D :D :D

0

The way I see it (my personal opinion) is that they included these C libraries in the C++ only to make the TRANSITION for all those C programmers easier, because in the past C was the dominating language in comparison to C++ and they didnt want the programming community to refuse migrating to c++....

Rationalize it however you want, the standard C library is included in standard C++.

>Nevertheless I prefer and try to use C++ characteristics.
That's fine. C++ is designed to support different programming philosophies.

>merge the C++ and C forums in one forum in this site
>since all these C libraries were included in the C++ standard
What a stupid comment. As long as I can write a program (without using libraries) that compiles and works as intended in C and fails to compile or fails to work correctly in C++, I will advocate two forums.

0

Hi its late./..
but if ur still searching then use Dev++

plz help and yes submit a direct link if u can and thx for advance plz hurry up i have assignment next week i have to finish it lol

0

it was good in its time

but its not been updated in a while

i think codeblocks is what is used now instead by most people

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.