C++ code

Can someone please explain how did the output turn out like this?

...

...

The function header (line #6) has default values for width and height if none are passed explicitely

look at the number of arguments you're using for calling AreaCube, retard

Are you... Are you actually serious?

>writes in c++
>but uses the language like c
why? why would you use c++ to write a program like that?

at least use curly braces for fucks sake, you're not supposed to write int length = 100, but int length{100} in c++

That's a terrible advice.

>>but uses the language like c

Better to code like it's c than like it's java.

>you're not supposed to write int length = 100,

Literally nothing wrong with that. Fuck off to the

What exactly is the problem? Those values are correct.

It's the advice that Barjne himself and every modern book on C++ will give you. How many relevant books have you read? That kind of assignment will protect you against all type conversion errors, it is a modern feature of C++ that should always be used.

t. brainlet
Just go read a book, or two or three, before giving advice online. Please, you're not good enough to be advising anyone on anything

the only time the {} list form shouldn't be used is when using auto to determine the type

it depends.

in the case of
$ int length = 100;
there's nothing wrong with it, since you're just initializing the int with a literal. as soon as we get to
$ int length = passed_in_from_somewhere;
land, we're allowing implicit, ie information-discarding, type conversion, whereas
$ int length{passed_in_from_somwhere};
will produce a compiler error when passing in a float.

however,
$ std::vector vec(5, 10);
and
$ std::vector vec{5, 10};
do vastly different things; one creates a std::vector, size 5, all 10s, the other creates a std::vector, size 2, 5 and 10.

the latter is the reason why using curly braces for initialization isn't best practice yet. however, i tend to teach favoring curly braces while being aware of fun issues with container/class initialization.

in the end, it remains a matter of opinion. just as C++ remains a language where you still, despite all C++11 and following mitigation efforts, must know what you are doing.

line 6 defines width and height, so when you call the AreaCube funct, it multiplies L W and H, rather than, lets say, just return length.

>#include
Stop coding like it's 1997. Use
>#include
>using namespace std;
Standard C++ doesn't support iostream.h

>AreaCube(int length, int width, int height)
You have to include the return type in standard C++; even in the definition after the declaration.
>int AreaCube(int length, int width, int height)

It doesn't matter much and you're missing more glaring errors in OP's code.

what a retard are you.

>why? why would you use c++ to write a program like that?
there is no default arguments in C, you have to write 3 functions.

>at least use curly braces for fucks sake, you're not supposed to write int length = 100, but int length{100} in c++
xor yourself.

this is what happens when mathfags try to program

OP clearly is a CS major.

>being aware of fun issues with container/class initialization
That was my point.

The language is very hard as it is and C++ is fixing old inconsistencies by introducing new inconsistencies.

You need to overload the function (declare the function with alternate amounts of parameters) if you want to be able to pass it with only 2 arguments. I assume you can do that in c++, Otherwise if you only pass 2 arguments you'll get unpredictable results, afaik.

>c++ is 2 hard

>The language is very hard as it is

No.

>I am ok with this

How about you start reading the source code of the libraries you use.

>not {{}}

pleb, hasn't /pol/ taught you anything

...

>implying sisper is impressive or anything not freshman level

I used to be addicted to c++ in my cs for engineers course last spring.

I used to lookup crazy advanced ways to solve stupid programming assignments like 'make a tic tac toe program' or 'make a shopping cart'

dont listen to these ppl saying 'eewww dirty code' or w/e

I'm a beginner but here's my take:

Using AreaCube() allows you to use main's values for length width and height rather than the default values.

Second area is using the main value for length and width and the default value for height outside of the main method. So 100*50*1 = 5000 (defaults are found in line 6)

Third area uses main value for length, and default value for width and height. So 100*25*1 = 2500

Hope it helps.