Working with variables in C++

Hey people! :smiley:

In this lesson we cover how to declare and initialize variables in C++ and how to output the value of them to the terminal.

We also learn how to use arithmetic operators to intialize our sum and product variables with expressions.

Did any of you try the other arithmetic operators? :eyes:

I probe all operators and also found another operator (%), what this operator does is assign to the variable the value of the waste in a division

7 Likes

I didn’t try other operators, however I did name my variables names as a, b, c, sum, and product are too ambiguous based on coding standards.
I named my variables outside of main to make them global and named them firstCodeNumber, secondCodeNumber, thirdCodeNumber, sumCodeTotal, and productCodeTotal.

2 Likes

@GavinMilroy Hi, im catching up with this talk about variables, arithmetic operators and etc… I just wanted to know is it ok to follow up without commenting everything here, cause it is the really basic stuff ( I’ve worked with python, mel, maxscript, and used blueprints lot in UE)? I’m reading every forum post for the current lecture I’m on.
I’m waiting to get to the bit more complex part to kick in…
Is that ok?

P.S. I really like the course, thumbs up for the great lessons! :smiley:

1 Like

Hi I did the basic programming without the other operators as told, and making the code easy to read. I thought I did pretty good. When using visual code is their a way to use screen capture without third part software.

fatal error C1083: Cannot open source file: 'triplex.cpp': No such file or directory did any one else get this error?

1 Like

fatal error C1083: Cannot open source file: 'triplex.cpp': No such file or directory did any one else get this error?

The files became inaccessible. You will need to fix path, files location, or files. You can also see if there’s an update for the code application you’re using should it be a bug.

1 Like

How can I fix the path or files and locations ??

I get it and don’t know anything how can I solve that .

Not really sure how to help you with that. It would be good for you to already understand that as its a part of development but far too complex for me to go into and too much stuff to go back and forth with.

I just recreated that error. It’s easy to fix. Visual Code is looking for a file that isn’t in your folder. If you go to the correct folder chances are all will be good. A couple of screen shots for you to check it out @ThePancake41

My end code was different, but produced the same result.
It looks like Gavin’s code is more efficient. What else am I missing? I’m new to coding.

i keep geting this and i cant work out why

:slight_smile: I am enjoyed this lesson so much, it feels like I am understanding the ideas well! You guy’s did a great job on this one :slight_smile:

1 Like

So I tried the different operators but I was more interested by how they added the angled brackets to include an ENDLINE after the COUT and get both functionalities within a same line.
Is this ability to concatenate functions within a namespace particular to the library or C++ syntax itself?
I assume I’ll arrive at the answer later on my own but just curious :slight_smile:!

Hello RynEllis,
I would recommend not using Global Variables and instead keeping them in local scope.

Hello Duderseb,
If I’m understanding your question correctly, it’s just syntax. The << just means I want to output something to the terminal or “Screen” and in the case of using std::endl or just endl, if you’re using using namespace std, you’re just saying I want to output a newline

const won’t let the value of variable change. It will keep on giving out the same value as declared even if we change the value of variable again at any part later.

Hey there! I am curios. In terms of initializing multiple variables, is it considered against coding standard to do something like

“int a = 2, b = 4, c = 6;”
instead of having it on three separate lines?
“int a = 2;
int b = 4;
int c = 6;”

Just seems to look, to me at least, nicer on one line instead of three.

i tried all the operators :slight_smile:

Privacy & Terms