ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

C++ FOR BEGINNERS (2020) - Ternary (Conditional) operator, How to Guessing game PROGRAMMING TUTORIAL

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ส.ค. 2024
  • What is ternary (conditional) operator and how it is used?
    In this video we'll build fun guessing game application using ternary (conditional) operator.
    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    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.
    Download Visual Assist here: bit.ly/WT-CB
    I use it to enhance the performance, features, and support for C, C#, and C++ development in Visual Studio.
    Download Ultra Edit here: bit.ly/UE_CB
    It is a powerful, secure text editor designed specifically for programmers.
    ☕ If you've found my content helpful and would like to support me, you now have the option to buy me a coffee or a cookie! It's a small gesture of gratitude that means a lot to me and helps me keep creating free educational videos for you. You can use the link below to make a contribution: bit.ly/CodeBeauty_BuyMeACoffee
    However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇
    Follow me on other platforms:
    Instagram 📸 - / truecodebeauty
    Twitter 🐦- / truecodebeauty
    ******CODE IS IN THE COMMENTS******

ความคิดเห็น • 67

  • @CodeBeauty
    @CodeBeauty  4 ปีที่แล้ว +21

    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    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
    using namespace std;
    void main()
    {
    int hostUserNumber, guestUserNumber;
    cout > hostUserNumber;
    system("cls");
    cout > guestUserNumber;
    (hostUserNumber == guestUserNumber) ? cout

  • @user-it3kv8fv6g
    @user-it3kv8fv6g 4 หลายเดือนก่อน +1

    Started learning C++ around 4 days ago, started with lots of reading and I felt like I was getting "mushy brain" from intaking too much information that I wasn't putting to practical use and it was hard to remember stuff, 9 videos in from your beginner course and what I've learned in that short amount of time has stuck and has gave me more knowledge than the 18+ hours I spent reading about c++. Your videos have helped that much that when you are explaining in the intro what you want said program to do before you start the tutorial I find myself inside visual studio writing what you are going to show and for this example I managed to write your first solution to the program using if/else and now have learned another way to get the same results. So glad you are the first channel I found when it comes to beginners tutorials because honestly it's so straight forward and easy to understand, I want to personally thank you for putting your time and effort into these videos and helping give me an outlet that will become useful during my life! Huge thumbs up from me.

    • @CodeBeauty
      @CodeBeauty  4 หลายเดือนก่อน

      Thank you for this comment! This is an old video of mine, and I usually don't get notifications for comments on old videos, but this one showed up on my screen, and I'm happy that my video helped you. If you ever decide that you want to sign up for a practical programming course (you can finish my playlists "C++ for beginners" and "OOP" first) then you're welcome to join my Practical Programming course to learn how to build real apps and start making money 😄😄

  • @nicklansbury3166
    @nicklansbury3166 4 ปีที่แล้ว +14

    This is a nice series with good, clear explanations. Thanks. Liked and Subbed.

    • @CodeBeauty
      @CodeBeauty  4 ปีที่แล้ว +6

      Glad to hear that. I'm really looking forward to building a community that is going to share knowledge, support and help to spread IT-oriented topics on TH-cam.

  • @bearsoundzMusic
    @bearsoundzMusic 3 ปีที่แล้ว

    Best explanation for ternary operator i have seen!

  • @dantepaperinosky25
    @dantepaperinosky25 2 ปีที่แล้ว

    Thanks video and thanks of your instructions. Greeting from Italy

  • @jerseychou4323
    @jerseychou4323 ปีที่แล้ว

    thank you

  • @Ryantcliff
    @Ryantcliff ปีที่แล้ว +2

    3:07 A better alternative to ‘system(“cls”)’ because of its lack of portability to other OS would be:
    #if defined(_WIN32) || defined(_WIN64)
    system(“cls”)
    #else
    system(“clear”)
    #endif

  • @gplgomes
    @gplgomes 3 ปีที่แล้ว +3

    You use system() commands. I sugest a lesson about its options and how to use it.

  • @Vanillaessence
    @Vanillaessence 3 ปีที่แล้ว

    Very much enjoying this series. I may finish all of them today. I know a tiny bit about loops so I was able to "upgrade" the code by allowing the host to set a maximum number of attempts and allowing the guest to guess that number of times and ends the program once the correct answer is given. I don't yet know the correct way to initialise a variable without giving it a value so I set guestUserNum = 0.
    #include
    using namespace std;
    int main()
    {
    int hostUserNum, guestUserNum, maxAttempts, attempts = 0;
    cout > maxAttempts;
    cout > hostUserNum;
    system("cls");
    while (attempts < maxAttempts)
    {
    cout > guestUserNum;
    (hostUserNum == guestUserNum) ? cout

  • @oussamabourouaiah6134
    @oussamabourouaiah6134 3 ปีที่แล้ว +6

    @CodeBeauty
    I've upgraded this game using while loop, and added some guidance to guest to go higher or lower.
    Also I've added a counter to counts how many time the guest tried until getting correct number.
    #include
    using namespace std;
    int main()
    {
    int hostUserNum, guestUserNum, counter1=0, counter2=0, counter=1; //counter is set 1 to include the first time guest enters a number
    cout

  • @leonidas1724
    @leonidas1724 3 ปีที่แล้ว

    If you guys want to customize your Code and make it Better than it is now, My Suggestion would be to use "(num1 == num2) ? cout

  • @Hylocichla
    @Hylocichla 3 ปีที่แล้ว +2

    Saldina, I started teaching myself C++ a month ago. In the last week I discovered your C++ Crash Course video and then your CodyBeauty channel. So far I have watched maybe 10 of your tutorials here. You are doing an outstanding job. Below is code that restricts the range of values the Host is allowed and gives the Guest three guesses. Even though I am using a ternary statement I still have an if-else statement. Maybe the code could be streamlined to put everything in the ternary statement and get rid of the if-else. I am wondering whether it would be easy to prevent the Host's selection from ever appearing on the screen so the host and guest could both be viewing the monitor at the same time.
    #include
    using namespace std;
    int main()
    {
    int hostUserNum, guestUserNum1, guestUserNum2, guestUserNum3 ;
    cout hostUserNum ;
    if(hostUserNum < 0 || hostUserNum > 10)
    cout guestUserNum2 >> guestUserNum3 ;
    (hostUserNum == guestUserNum1 ||
    hostUserNum == guestUserNum2 ||
    hostUserNum == guestUserNum3)? cout

  • @mhdjaseem3195
    @mhdjaseem3195 2 ปีที่แล้ว

    thanks, mam💕💖

  • @Menahel19
    @Menahel19 2 ปีที่แล้ว

    you are the best

  • @ROYALNIL_SITE
    @ROYALNIL_SITE 11 หลายเดือนก่อน

    thanks saldina

  • @hilaltemel1830
    @hilaltemel1830 7 หลายเดือนก่อน

    hi dear @CodeBeauty I can't clear my screen output with system("cls") is there any other way to clean it?

  • @padmasekar
    @padmasekar ปีที่แล้ว

    why mam you didn't use a paranthesis in if else statement

  • @Mayeloski
    @Mayeloski 2 ปีที่แล้ว

    Hey, I have a question, according to your example that we ask our user to write a number, how we can stop the program for "invalid value" if the user write a string or vice versa, with the if statement? I've writen this but I don't know how to put the condition that if the inputs are number or strings, I don't know if you get what I'm trying to say.
    string hostName, guestGuess;
    cout > hostName;
    system("cls");
    cout > guestGuess;
    if (guestGuess != ... || hostName != ... ) {
    cout

  • @MohamedGamal-ci2ti
    @MohamedGamal-ci2ti 2 ปีที่แล้ว +1

    What is the shortcut key that make multi line comment in visual studio by ?

    • @CodeBeauty
      @CodeBeauty  2 ปีที่แล้ว +1

      Mark the lines that you want to comment, hold Ctrl, pres K and C

  • @laxus7764
    @laxus7764 3 ปีที่แล้ว +1

    i tried using them in nested form , can we do that?

    • @CodeBeauty
      @CodeBeauty  3 ปีที่แล้ว +2

      It can work, but I personally never nest ternary operators, because their main purpose is to make code shorter and easier to read, and if you nest them, it'll just make your code more confusing, so nested if/else is a better choice. 🤔🤓

  • @Ace-cq7jl
    @Ace-cq7jl 4 ปีที่แล้ว

    Kako da zaustavim goto statement da se iznova i iznova ne vraca na pogadjanje broja. Umjesto toga da se program sam iskljuci kada se pogodi tacan broj. U LibertyBasic.u koliko se sjecam radilo se preko "while " petlji..

    • @CodeBeauty
      @CodeBeauty  4 ปีที่แล้ว +1

      Da, to mozeš uraditi preko petlji :)
      Naredni video koji ću postaviti će biti upravo while petlja, tako da možeš tu pogledati kako radi. Staviš u petlju uslov, na osnovu kojeg će ona znati koliko ponavljanja će uraditi, pa tako možeš npr. dati korisniku mogućnost da ponavlja 3 puta ili dok ne pogodi. :D
      taj video će biti postavljen večeras :)

    • @CodeBeauty
      @CodeBeauty  4 ปีที่แล้ว +1

      th-cam.com/video/qGKCnTq8CqQ/w-d-xo.html Ovdje možeš pogledati kako radi while loop! :)

  • @milanrai1556
    @milanrai1556 2 หลายเดือนก่อน +1

    not working with macOS : system("cls") to clear the console. any better option??

    • @CodeBeauty
      @CodeBeauty  2 หลายเดือนก่อน

      Hey please watch my video about system pause, that will explain how to do it on mac

    • @milanrai1556
      @milanrai1556 2 หลายเดือนก่อน

      @@CodeBeauty sure ❤

  • @deathraze9
    @deathraze9 3 ปีที่แล้ว

    9:15

  • @Thebiggame-dc8ek
    @Thebiggame-dc8ek ปีที่แล้ว

    How do you select all lines and make them a comment by typing */ only once?😮

    • @yevgeni10
      @yevgeni10 ปีที่แล้ว +1

      Ctrl K then Ctrl C

  • @tawansiforlifetfl9987
    @tawansiforlifetfl9987 3 ปีที่แล้ว +3

    Would love to know what you think?
    #include
    using namespace std;
    int main()
    {
    int hostNumber, guestNumber, difficulty;
    cout

    • @Wolfgirl-bi7ie
      @Wolfgirl-bi7ie 2 ปีที่แล้ว

      Wow that is a lot of code. You made into much more of a complex game!

    • @Wolfgirl-bi7ie
      @Wolfgirl-bi7ie 2 ปีที่แล้ว

      I tried your code, and I chose the easy difficulty and input the number 2 for the host but when I tested it as the guest then it didn't work properly. I used the right number as my second guess. after further testing with this code the only time I could guess correctly was when the first guess was correct. I am currently trying to make my own version of the code using yours as a baseline since I like the idea but I am only going to give the user 1 guess at first so I can make sure that my code will work then I will try to give chances. After I get done with my code, I will come back to yours and see if I can figure out what the problem was and if I can figure it out then I will post a revised copy of your code.
      Sorry if I seem rude, I am just trying to further my knowledge of coding, and this would be good practice. It would also give future viewers a better functioning code to base off of.

  • @imnot9923
    @imnot9923 ปีที่แล้ว

    Comment for Algor

  • @yodhedesta1406
    @yodhedesta1406 3 ปีที่แล้ว

    how is this?
    using namespace std;
    #include
    #include
    int main()
    {
    cout

  • @findikbabi
    @findikbabi 4 ปีที่แล้ว +1

    This is my code
    int hostUserNum, guestUserNum;
    cout > hostUserNum;
    if(hostUserNum >9)
    {
    cout guestUserNum;
    (guestUserNum == hostUserNum) ? cout

    • @CodeBeauty
      @CodeBeauty  4 ปีที่แล้ว +1

      Hahah, great! Love your creativity 😁
      And if you continue this playlist and watch videos on loops, you will get an idea on how to let your user to guess the number multiple times! 😏

    • @findikbabi
      @findikbabi 4 ปีที่แล้ว +1

      @@CodeBeauty Thank you!

  • @bielhelp
    @bielhelp หลายเดือนก่อน

    Solving with strings:
    #include
    using namespace std;
    int main()
    {
    std::cout

  • @mr.faisal1708
    @mr.faisal1708 3 ปีที่แล้ว +3

    Hoping to get kidney from you, becz getting heart is impossible. :-(

  • @SebleBeyene-jp8hp
    @SebleBeyene-jp8hp 3 หลายเดือนก่อน +1

    I see*2 gambling mine game was scam 💀😭 2:54

    • @CodeBeauty
      @CodeBeauty  3 หลายเดือนก่อน

      😅😅

  • @mareklewanski2198
    @mareklewanski2198 3 ปีที่แล้ว

    #include
    using namespace std;
    int main()
    {
    int hostUserNum, guestUserNum;
    cout > hostUserNum;
    if (hostUserNum >= 1 && hostUserNum

  • @pieterpennings9371
    @pieterpennings9371 ปีที่แล้ว

    #include
    using namespace std;
    int main()
    {
    int CorrectNum = 11, Guess, tries = 0;
    cout 10 || CorrectNum < 0){
    cin >> CorrectNum;
    if(CorrectNum > 10 || CorrectNum < 0)
    cout Guess;
    (CorrectNum == Guess) ? cout

  • @raomudasir4509
    @raomudasir4509 3 ปีที่แล้ว

    Here is the code
    #include
    #include
    using namespace std;
    int main()
    {
    cout

  • @stevennichols3421
    @stevennichols3421 2 ปีที่แล้ว

    I found a bug where if you entered a non integer it would throw the program into an infinite loop, I fixed that and output an invalid entry, added a while loop to keep guessing until correct and if statements to tell if guess to high or low.
    #include
    #include
    int main(){
    int hostUserNum, guestUserNum;
    std::cout > hostUserNum;
    system("clear");
    if(!std::cin){
    std::cout > hostUserNum;
    system("clear");
    }
    std::cout > guestUserNum;
    /*(hostUserNum == guestUserNum)? std::cout hostUserNum){
    std::cout > guestUserNum;
    }
    if(guestUserNum < hostUserNum){
    std::cout > guestUserNum;
    }
    }
    std::cout

  • @AlfraRed
    @AlfraRed 2 ปีที่แล้ว

    /* A guess the number code which allows an initial input (User 1) and 3 guesses (User 2). Windows compatible only,
    until I can figure out how to incorporate a multi-platform friendly delay feature 😊(Hence the Windows library header)*/
    #include
    #include
    #include
    using namespace std;
    int main() {
    int number, guess;
    char Again;

    cout number;
    system("cls");
    for (int i = 1;i

  • @AlfraRed
    @AlfraRed 2 ปีที่แล้ว

    /* A guess the word program which allows an initial input (User 1) and 3 guesses (User 2). Windows compatible only,
    until I can figure out how to incorporate a multi-platform friendly delay feature*/
    #include
    #include
    #include
    using namespace std;
    int main() {
    string word, guess;
    char Again;
    cout word;
    system("cls");
    for (int i = 1;i

  • @Biohaze89
    @Biohaze89 2 ปีที่แล้ว

    int hostUserNum, guestUserNum;
    cout > hostUserNum;
    } while (hostUserNum < 1 || hostUserNum>15);
    system("cls");
    cout > guestUserNum;
    } while (guestUserNum < 1 || guestUserNum>15);
    (hostUserNum == guestUserNum)? cout