Buckys C++ Programming Tutorials – 25 – switch

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Comments

21 responses to “Buckys C++ Programming Tutorials – 25 – switch”

  1. Muhammad Nouman Avatar

    Thanks Sir , you teach us for free

  2. Hari Shankar Avatar

    Can someone explain to me how he saved time by using switch statement? Repeated if statements would be approximately same amount of typing

  3. Marcell D Avatar

    instead of exact of number in the case can I make sth bigger or lower to (<,>,<=,>=)?

  4. WALLSNAP Avatar

    switch is not in programming language python U WERE WRRROONNNGGG

  5. Bleen Paper Avatar

    haha, here in Germany I can buy beer with 16 xD

    gg ^^

  6. DrToonhattan Avatar

    Man, these ages seem so odd. In the UK you have to be 16 to play the lottery, 17 to drive, and 18 to buy alcohol. Really couldn't imagine going through university without being able to drink, that's like 90% of British student culture.

  7. Matthew Bird Avatar

    Christ. He can't even explain simple keywords like 'break'. Disastrous. Creating a generation of shit programmers.

  8. zubair the geniuse Avatar

    what's the use of #include <cmath> …………… please some one tell me.. wht the fuck does it do…

  9. Khalil Rouatbi Avatar

    are there any lectures notes available?

  10. Niharika Singh Avatar

    Why can't we use switch statement with strings? Is there a way around it?

  11. Tarun Chand Avatar

    for those who faced the same problem as me while trying to put in a range of values ( like from age 0 to 16, age 17 to 20 etc), do this:
    case ( starting value … end value): code here;
    break;
    and be sure to put the space before and after … otherwise it will think you are putting decimal points.
    example:
    case 0 … 16: cout << "quite young";
    break;
    case 17 … 25: cout<< " whatever";
    break;
    default: cout<< "you get the picture";

  12. ThunderDoes Gaming Avatar

    Used this to make a calculator ;D

    #include <iostream>
    #include <cmath>
    #include <string>
    using namespace std;

    int main()

    {
    int x;
    do{
    cout << "Enter a mode!" << endl;
    cout << "1)Add, 2)Subtract, 3)Multiply, 4)Dividen";
    cin >> x;
    switch(x){
    case 1:
    int a;
    int b;
    cout << "Enter the numbers you want to add!" << endl;
    cout << "Number: ";
    cin >> a;
    cout << "Number: ";
    cin >> b;
    cout << "The answer is: " << a + b << endl;
    break;

    case 2:
    int c;
    int d;
    cout << "Enter the numbers you want to subtract!" << endl;
    cout << "Number: ";
    cin >> c;
    cout << "Number: ";
    cin >> d;
    cout << "The answer is: " << c – d;
    break;

    case 3:
    int e;
    int f;
    cout << "Enter numbers you want to multiply!" << endl;
    cout << "Number: ";
    cin >> e;
    cout << "Number: ";
    cin >> f;
    cout << "The answer is: " << e * f << endl;
    break;
    case 4:
    float g;
    float h;
    cout << "Enter the numbers you want to divide!" << endl;
    cout << "Number: ";
    cin >> g;
    cout << "Number: ";
    cin >> h;
    cout << "The answer is: " << g / h << endl;
    break;
    default:
    cout << "Please try again. That is invalid.n";
    }

    }while(x != 1,2,3,4);

    }

    // for(int x = 5; x < 50; x+=5) (Start, End, How much to go by)

  13. Alfred Lewis Avatar

    why if we change the age from 16 to let's say int age = 16.78 the switch will give you the answer as if age were the case 16???

  14. Johnathan De leon Avatar

    Thank your for the videos! Definitely a great help!

  15. Kugel Avatar

    can we do something other than just compare int values, does it work with chars and doubles , and whatnot?

  16. RainycornX Avatar

    Lol Nintendo Switch statement

  17. Kugel Avatar

    can we do things other than cout within a switch statement?

  18. Orangejuice9000 Avatar

    It might be worthwhile to note that you can't use "<" or ">" in switches. For example, "case <16:" will throw an error.

    Use if-statements instead.

  19. Andrei Bercea Avatar

    Oh my god! Thank you! Switch is so useful. It saves so much time from trying to make sense of brackets when you're using too many nested if or if/else statements. 😀

Leave a Reply

Your email address will not be published. Required fields are marked *