C++ FOR BEGINNERS (2025) - Switch/case statement, How to check days in a month PROGRAMMING TUTORIAL

preview_player
Показать описание
What is switch/case statement and how it's used?
In this beginner-friendly C++ programming tutorial, switch/case statement is explained while building a program that has to write out how many days there is in each month of any year.
Also pay attention to the second month (February), because in the case of leap year it is going to have 29 days, and if not, it has 28 days.
I hope that you'll like this video. Make sure to subscribe, and also check out other videos of this course.

📚 Learn how to solve problems and build projects with these Free E-Books ⬇️

Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

Follow me on other platforms:

*******CODE IS IN THE COMMENTS*******
Рекомендации по теме
Комментарии
Автор

📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

#include <iostream>
using namespace std;

void main()
{
//(year % 4 == 0 && year % 100 !=0 || year % 400 == 0)
int year, month;
cout << "Year, month: ";
cin >> year >> month;

switch (month)
{
case 2: (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ?
cout << "29 days month" : cout << "28 days month"; break;
case 4:
case 6:
case 9:
case 11: cout << "30 days month"; break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: cout << "31 days month"; break;
default: cout << "Not valid!";
}

system("pause>0");
}

CodeBeauty
Автор

You make it so simple to understand. Thank you for Your work!!! :)

soldierschrist
Автор

Thanks for all these tutorials, I love that they are short and straight to the point without lots a techno speak that you get from other people. That makes them easy to understand for people that only have a basic understanding of programming, I've had a look at other tutorials in the past - but I found yours to be of excellent quality and just the correct length of time so that we are not overwhelmed with too much information at once. Also it's good that way because if we just want to go back over a subject such as if/else etc, it's easy to find.
Keep up the good work - you are doing a great job and thank you very much for posting these.

mrdude
Автор

Fall through can be a very useful feature of switch; example when condition X requires actions 1, 2, 3 ; Y requires 2 and 3 ; and Z only needs 3 it is easy to use fall through. And you are not limited to integer cases, it will accept enumerable types.
I haven't tested but I speculate that because switch acts more like a lookup table rather than accepting complex expressions, it likely has a big performance advantage over a complex if statement structure. The if statement structure would require separate inline evaluation of every case until finding true. Sort of analogous to compiled verses interpreted source code. As such I would see if as more useful for a single evaluation and switch should execute faster in a high demand loop situation.

mytech
Автор

Thank you for your videos, you are a really good teacher. I couldn't understand C++ before I watched your tutorials. I found the flow charts in earlier lessons really helpful because I could have a go at writing the code on my own from the information on the flowchart, and if I got stuck or didn't know how to do it I could just wait to see how you did it. Thank you again :)

margotalmanzar
Автор

Your explanations are great! Awesome job! Keep up the good work!

markontech
Автор

Great tutorial and better than the version I tried to make in QB64 a couple months ago.

wattstudio
Автор

These tutorials are so helpful! Thank you for fully explaining everything! I’ve been able to write original code thanks to your videos 🖤🖤

seraphinamorrison
Автор

Excellent series, well presented, you have my thanks :)

GregJones-ccsk
Автор

Thank you very much!. You are so I hope you will be a university lecturer so that I can learn from you

mohtdips
Автор

Lovly to see ur all videos. Though i know switch statement, i love to see ur face again n again❤️❤️❤️❤️❤️

Sekhar_Home
Автор

Your explanation is more useful for me to understand you say me....how many days took you to become a well developed in reply

chaneditz
Автор

what is the difference by using printf instead of cout? also can printf be used instead of cin?

hendrikl
Автор

Definitely helpful! ❤️ College student all the way from the Philippines. Hoping that we can be friends! ❤️

jmrbautista
Автор

Can you also say
switch (month){
case month 2:(somefunction);
}
Should that run the same as if you put only "case 2:()"?

BAMBAMBAMBAMBAMval
Автор

Hello Saldina, and thank you for your work. I'm obviously a beginner programmer and what I would like to know is that: I tried "Tutorial 10 programming" and, "8" with Microsoft's Visual Studio; and I couldn't do the "switch" statement.<I mostly did "Tutorial 7">. Are there "side Tutorials" that focus on one thing like a switch statement?

meirrubenstein
Автор

how can we use switch case in while loop?

artsbylaiba
Автор

Hello Saldina, this is othman from Tanzania, i just want to ask, how can someone be a C++ developer ? i.e what are the steps to follow in order to become a C++ developer ??

shabanimhando
Автор

Hi Saldie, i am new. I try to learn C++ with you. I'm not english at birth but i understand what you said. My question is simple : Is it normal i understand each comprehension about swtich and variables or conditions etc. But, i dont have this kind of logic to see what can i do. But when you put code after i understand perfectly... Is it normal am i stupid lol ? Seriously ?

SupraZelda
Автор

i understoo mostly eveything the only thing im confuse about the leap year formula...if i had to make it in top of my head i just wouldnt know how to do it...can someone explain it like im a 5 yr old?

rrivera