C++ Tutorial: Day 3
EDIT: Day 4 Is TOTALLY not DElaYeD
Day 3: Conditionals and Headers
Thank you to.....
IF SOMEONE WOULD HELP ME EXPLAIN EVERY SINGLE HEADER PLEASE CONTACT ME IN THE COMMENTS BELOW
@DynamicSquid for header emphasize
@awesome10 wanted conditionals.
A emphasize on Headers
I realized I never really went in deep with headers in C++, so here is a bunch of headers that you need or want.
Literally just use #include <bits/stdc++.h>
to avoid the hassle. It has every single header that you need all in one.
Day 3!
Conditionals
What are conditionals?
Conditionals are expressions that evaulate to either true or false. They are usually used for if, else, and while loops.
If Statements
If statements are used to execute code only if the condition is true.
If the statement is false, the expression is just ignored, and the program will continue to run.
Example:
int x = 8;
int y = 5
if (x < y) {
cout << "x might be greater than y";
}
Else Statements
Else statements are the opposite of a if statement. Else statements will only be runned(ran? someone tell me what it is.) if the condition is FALSE
Example:
int x = 5;
int y = 8;
if (x < y) {
cout << "X is greater than y." << endl;
} else{
cout << "Y is greater than X." << endl;
}
Explanation: y is greater than x, so that must mean that the if statement is false. Therefore, the program would move on to the else
condition and print "Y is greater than X"
(Do you guys need else if?)
While Loop Statements
Loops (can) execute a block of code as long there is a condition that is specified.
Loops are awesome because they make your code look cleaner. (my code is not clean btw)
While loops only loop through a block o code as long as a specified condition is true:
Example:
int i = 0;
while (i < 10) {
cout << i << "\n";
i++;
}
This program will loop over and over again as long as the variable i is less than 10.
That's it!
Upvote?
Thanks for 400 cycles guys
Credits:
w3schools.com
sololearn.com
Featured Shoutout....
@Muffinlavania
Featured Shoutout....
@DyanamicSquid for all my shoutouts.
If there are any bugs or typos, please feel free to tell me.
Honk Honk YES! @DannyIsCoding (totally not stolen from me)
I really like this tutorials 👍
HeHeHooHooHonkJongBonkTronkBeepBoop YES! (Too far? maybe...)
@DannyIsCoding Your quote will be in the next series
@HahaYes lol thnx i quess xD
@DannyIsCoding lol share this with others so it gets lots of views
@DannyIsCoding You literally forgot quack
@awesome10 oh no we forgot danny
Also, I think that #include<bits/stdc++.h>
is bad practice. It makes your binary's fat, and abstracts what you need.
@CodeLongAndPros alright, I'm a competitive programmer, so it is a habit of mine
Header Files
One way to make your code more organized and neat.
Header files are as cool and handy as heck.
A header file is a C++ file which you can use import in a header
A C++ header file's file extention is .hpp
.
Make a file with the .hpp
file extension and write your C++ code in there.
To use your C++ header file use #include "headerfilename.hpp"
, of course, replacing headerfilename
with the name of your header file.
Voila! Now you know what header files are and how to use them.
BTW there are also C
header files. In case you were wondering.
@nk1rwc yes, will continue this series :)
@HahaYes YEEEEEE
@HahaYes Haha yes..
@Muffinlavania Muffin the day 4 is out
@HahaYes yessir i know... you kinda said every one of our names which meant it was in our notifications..
@Muffinlavania yes, free ads are the best
@HahaYes We take those
@Muffinlavania yum yum
YESSIRRRR
@HahaYes
@DevJoshua YesssSSSsss
Day1: 10 days ago
Day2: 9 days ago
Day3: 5 days ago
WE DEMAND A DAY FOUR
@SpaceFire brb I'm sick......... I'm trying man
@HahaYes oh... i'm sorry bro
now i just feel bad
@HahaYes Get well soon!
@SpaceFire hmmmm hope I don't get sicko sicko
@HahaYes what?
@SpaceFire hope I don't get sick from that
@HahaYes oh ok... have fun?
@SpaceFire ummmm sure.... hmmm looking forward to hire people for day 5
@HahaYes # PLEASE TAKE ME WITH YOU
pls day 4
@SpaceFire # Coming VERY VERY SOON
@HahaYes # bringeth the knoweldge bestowed upon thy noggin
You said to use <bits/stdc++/h>
, but I would suggest not to, as it makes it more readable to lower-level people to see where each function and class is coming from. Just a suggestion.
@ipastrano yeah, I will put that later
Thanks for 500 cycles guys!
can't wait for day 4
Literally just use #include <bits/stdc++.h> to avoid the hassle. It has every single header that you need all in one.
Don't. It's terrible. It's mich better to just use each individual one
@DynamicSquid lol I'm a competitive programmer, it is just a habit of mine
Do you feel proud of yourself for becoming replit's inside meme?
@SpaceFire Wait I'm a meme now? I feel awesome
@HahaYes haha, yes yes you are.
@SpaceFire HAHAYESssss
@SpaceFire Feel free to upvote
i did a code, are you proud of me? lol my fantastic code
@SpaceFire the only thing i looked at in that was the minecraft icon
@SpaceFire i like minecraft ok?
@awesome10 so do I thats why i have it
@SpaceFire well duh
What should I do for the next one?
@HahaYes check your cycles, your pretyyyyyy popular
@HahaYes You should do namespace
and class
@HahaYes do they have for loops down by these C++ parts
@HahaYes in python and javascript we use for loops. does c++ have them?
@CodeLongAndPros yeah....but that is oop and that is a little harder
@SpaceFire yeah you want that in next tutorial?
@Muffinlavania but how.... someone cycle farmed?
@HahaYes that would be nice because we would have completed the two types of loops of loops. Also, do we have elif/else if
@CodeLongAndPros is class a little bit too advanced?
@HahaYes Not really.
@HahaYes For loops. If else. For the if else, explain all the relational operators and the AND
, OR
, and NOT
stuff. I don't think you should do classes yet, wait until your readers have more of the basic stuff down. Oh and also maybe switch
in the next one, or the one after.
@ipastrano do you want to help me with it?
@HahaYes Sure!
yay i was mentioned!
@HahaYes HahaYes
Ayy idk why i get a shoutout but we take those :D
@Muffinlavania Haha YES!
@Muffinlavania @HahaYes You said thanks for 400 cycles... Then you blew up and got 500
@Muffinlavania lol it is great
@HahaYes 👍