hi every body>>>>
please i am student and this my homework very important to me
the question is :
how to complete this simple program to make its return 0 ?????
the answer is some thing instead of:

/*
	some statments
	*/

please i am new here and need ur help plezzzzzzzzzzzz

void function(int arg)
{
	char chars[10];
	/*
	some statments
	*/
}

void main()
{
	int arg=0;
	function(5050);
	arg++;
	cout<<arg;
}

return 0; might be a good idea, no?
That requires you to fix the return type of function, though.
And you need to fix the the return type of main too, because it always must be int anyway.

No One Here to do your homework. Just try your self and put what you have tried till now.

Edited 6 Years Ago by sundip: n/a

Why do you want to return 0? What is it you are trying to make your program do?

Returning an int from main() is what is required by the standard. The normal return from main() to indicate no errors occured is zero (0). Thus, the absolute minimum standards-compliant program is:

int main() {
  return 0;
}

Returning an int from main() is what is required by the standard. The normal return from main() to indicate no errors occured is zero (0). Thus, the absolute minimum standards-compliant program is:

int main() {
  return 0;
}

Yes I know, I was asking him.

Edited 6 Years Ago by Akill10: n/a

Yes I know, I was asking him.

Sorry, you're a pretty new poster so it didn't come across that way. For me anyway...

Edited 6 Years Ago by Fbody: n/a

Sorry, you're a pretty new poster so it didn't come across that way. For me anyway...

No problem, I guess I will just have to clock some more posts on the site! Even though I am no expert in C++, I do pride myself on learning a slight amount in the past 2 years :)

i am very sorry because you all did not understand me at first time because the question is completing the function with some thing instead of ::
/*
some statements
*/
and never never change any thing else
finally the return on the screen must be 0(in other way:the variable (arg) must equal -1 after call the function......

note::i am not a tyro student, i am c programmer from 6 year so :this problem is very very hard do not flout it

i am very very sorry but i really need all ur help

Returning an int from main() is what is required by the standard. The normal return from main() to indicate no errors occured is zero (0). Thus, the absolute minimum standards-compliant program is:

int main() {
  return 0;
}

Actually, the minimum standard-complaint C++ program is:

int main() {
}

Because in the C++ standard (3.6.1. part 5) it reads:

If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;

@OP: I still have no clue what you want. Try defining the problem in proper English instead of using this chat-lingo. Also: give us an example of the input and desired output of the function.

no i do not want 0 at cout
0 is the value of the variable (arg)
pleas read the code slowly again ...

thanx to every help...

just need to complete the function without anyyyyyy changing in other lines of program .....

Although I am new at this program, as far as I know return is used at main program
I think that void main() was wrong , it should be int main().... your should use return inside.

Comments
Did you even read the rest of the thread?

you try this may be it works

int main()
{
cout << "Press enter to continue" << endl;
cin.ignore();
return 0;

}

Edited 6 Years Ago by Nick Evan: Added code-tags

no i do not want 0 at cout
0 is the value of the variable (arg)
pleas read the code slowly again ...

...

If you continue to rebuke posters, they're going to stop helping you. Your code is very straight forward, it doesn't require any special reading. The problem is that your initial query doesn't make sense. You're not going to get a return value of zero (0) unless you use a return statement. As written, neither of your functions can use a return 0 because their return types are set to void (which, by the way, is NOT correct for main(), it must always return an int).

Your current code produces a single zero (0) on the screen, if that's all you need, that's what you have. Your function(int) does absolutely nothing for you, it's a waste of space and computing time.

If you mean something else, you'll have to re-explain it more clearly. Is this supposed to be an assignment concerning reference and/or pointer parameters for functions? If so, the code you have posted is not even close.

Edited 6 Years Ago by Fbody: n/a

Your current code produces a single zero (0) on the screen, if that's all you need, that's what you have.

I think it would currently return a one (1) as there is a arg++; just before the cout<<arg;

I believe he is asking if there is a way of modifying the arg value in main from function(int) to make it equal -1 (so that when it is incremented and printed it will equal zero) even though it has been passed to the function by value.

As far as I know there isn't without changing at least some of the code but I guess there must be if you have been set this as an assignment.

If you are able to change void function(int arg) to void function(int &arg) that would work obviously as you could modify the arg value but I guess that is not allowed.

Ragards,
Colezy

Edited 6 Years Ago by Colezy: n/a

I think it would currently return a one (1) as there is a arg++; just before the cout<<arg;

Okay fine, I somehow missed a line...

I believe he is asking if there is a way of modifying the arg value in main from function(int) to make it equal -1 (so that when it is incremented and printed it will equal zero) even though it has been passed to the function by value.

This is at the heart of what I'm getting at. The problem is, arg isn't the argument to the function call. The argument to the function call is hard-coded as a literal 5050, then the parameter arg receives 5050 by value, not 0. In fact it receives nothing even remotely related to main::arg.

I've been watching this thread since it was originaly posted. I haven't posted until now because it didn't make sense. In fact, it still doesn't.

Due to their reactions to posts thus far, at this point it seems clear to me that either the OP wrote an errant main() themselves, and stubbornly refuses to admit just how crappy it is and make changes, or their professor is a complete moron.

Edited 6 Years Ago by Fbody: n/a

The argument to the function call is hard-coded as a literal 5050, then the parameter arg receives 5050 by value, not 0. In fact it receives nothing even remotely related to main::arg.

Ah yes, now I missed a line haha.

I agree, as far as I can see this is not at all possible... and if his tutor gave him the code exactly as he typed it with the erroneous void main instead of int main then I think you may be right about his tutor ;)

Colezy

Edited 6 Years Ago by Colezy: n/a

Ah yes, now I missed a line haha.

...

Meh, it happens. :P :D

Edited 6 Years Ago by Fbody: n/a

no my friends...
the code has not any error and it is a void main and a void function ,just we must complete the function to call it at main then the variable arg will equal -1 after call the function then like what you see arg++ .................

thnxxxxxxxx for every help.....

Comments
I hope you're just a bad troll...
*sigh*

This very much looks like a 'trick' question of some sorts. So assuming that the requirements are that 1) the output must be zero (0) and 2) only the comment block is to be modified .. it can be done in standard C++, here's a hint, replace

void function(int arg)
{
char chars[10];
/*
some statments
*/
}

with

void function(int arg)
{
char chars[10];
#define <something here>
}

So, "<something here>" needs to be replaced with something.

Did you write this, or did your professor? It is possible to do what you propose, however, as written, what you propose to do is not possible. Everything related to your function called "function()" is not correct. You haven't declared it in a way that would allow it, you haven't implemented it in a way that would allow it, and you haven't called it in a way that would allow it. Nothing is correct.

Now, if you wrote this yourself it's time to own up and correct what we tell you to correct, or you're not going to get much, if any, farther.

EDIT:

This very much looks like a 'trick' question of some sorts. So assuming that the requirements are that 1) the output must be zero (0) and 2) only the comment block is to be modified .. it can be done in standard C++, here's a hint, replace

void function(int arg)
{
char chars[10];
/*
some statments
*/
}

with

void function(int arg)
{
char chars[10];
#define <something here>
}

So, "<something here>" needs to be replaced with something.

Hunh????? :-O :-/ :confused:

Edited 6 Years Ago by Fbody: n/a

*deleted*

Sorry, must have hit submit before completing actualy post which is below.

Edited 6 Years Ago by kes166: n/a

>> This very much looks like a 'trick' question of some sorts.

Good lord, I see what you mean.. If the teacher actually gave this assigment (s)he should be fired for encouraging this abomination of a code...

Hunh????? :-O :-/ :confused:

In this case, let's just put aside the non-standard code presented by the OP plus the seemingly 'impossible' basic requirements. It's quite obvious that the "void main()" etc. is not the key topic here, at least from the OP's viewpoint.

Again, like I wrote above, a simple #define solves this 'problem' in 100% standard and portable C++ code. As far as I can see, the only good outcome of this exercise for the OP would be to realize the possible dangers of using macros (e.g. using #defines carelessly).


@OP
It would actually be nice to know how come you are facing this dilemma, would you care to share that with us?

void function(int arg){
	char chars[10];
	/*	some statments	*/
} 

void main(){
	int arg=0;
	function(5050);
	arg++;
	cout<<arg;
}

SOME compilers allow void main. However, it is terrible programming practice to do so. When a program runs and completes, after the program completes, it sends a value to signify that it terminated successfully or unsuccessfully. If it is a void main, the value is random, generally a garbage value. If that value is outside a certain range, the program fails.

If you use int main, the program can return the appropriate value. You are taking an unneseccary risk in using void main.

Additionally, you have int arg in your main. This variable IS NOT the same variable as the one in your function. When you declare a variable, it assigns it appropriate memory space.

int arg = 0;

That assigns arg as an int value (I think 8 bytes).

void function(int arg){
	...
} 

void main(){
      ...
     function (5050);
      ...
}

That passes 5050 to a completly new memory location outside the function main and assigns it to a new variable called arg. arg in the function has no relation to the arg in main. The arg in main is beyond the scope of the function function to change. When your program terminates, arg in main will increment by 1, and have the value of 1. There is nothing you can do (to my knowledge) that will let you change arg in main by modifying code in function.

>> This very much looks like a 'trick' question of some sorts.

Good lord, I see what you mean.. If the teacher actually gave this assigment (s)he should be fired for encouraging this abomination of a code...

--- wait --- see my above post about the possible good outcomes of this problem .. let's not fire the teacher yet, right? ;)

Comments
Hmmm.. I'm still not convinced, but I see your point :)

>> This very much looks like a 'trick' question of some sorts.

Good lord, I see what you mean.. If the teacher actually gave this assigment (s)he should be fired for encouraging this abomination of a code...

Okay, so I'm not the only one that thinks that's obscenely weird.

EDIT:
Wow, I'm slow, I'll have to get caught up...

Edited 6 Years Ago by Fbody: n/a

This question has already been answered. Start a new discussion instead.