Facebook – https://www.facebook.com/TheNewBoston-464114846956315/ GitHub – https://github.com/buckyroberts Google+ …

source

41 Comments

  1. Here's what I tried to do, Input any number with decimals or just a number. If it's an int it will print "I am printing int" if it is float it will print "I am printing float"

    But it doesn't work, not sure why:

    #include <iostream>
    using namespace std;

    void printnumber (int x){

    cout << "I am printing an integer " << x << endl; //leave a space before quotes end to avoid text running together.
    }

    void printnumber (float x){

    cout << "I am printing a float" << x << endl;
    }

    int a;
    float b;

    int main()
    {

    Cin >> a||b;
    //int a = 54;
    //float b = 65.6789;

    printnumber (a);
    printnumber (b);

    return 0;
    }

  2. I'm not sure how "behind the scenes" this is, since one would still have to type in a number that is an integer in (a) and a float in (b). I thought it would be cool to try to make it ask for a number using CIN doing more like you seem to be describing, but couldn't figure out how to make it work.

  3. Also you can do void printSomething (int x , float x) , same concept just putting both variables in one function.

  4. 2 years… didnt understand a shit … and here.. hardly 6 minutes and i understood it .. dont know how to thank you ! tysm !

  5. I have watched this video . Now I am looking forward to one milion dollars to come. I hope this won't overload me.

  6. For what hell is it needed anyway?
    Just to ease source code modification?
    Which function to call is determined at compile time.
    Wouldn't that be easier to create truncating function that can solely accept all primitive types and do the job?

  7. why does printN(a*1.) say it's double?

    void printN(int n)
    {
    cout << "integer " << n << endl;
    }
    void printN(float n)
    {
    cout << "float " << n << endl;
    }
    void printN(double n)
    {
    cout << "double " << n << endl;
    }

    int main()
    {
    int a=23;
    float b=23.23;

    printN(a*1.);
    printN(b);
    }

  8. I have a question can I make a program in which suppose we let the user enter a number and the user enter a number like 32.90898 and make the result print like "its an integer" instead of giving value to the variables can we make user to give the value and print out the result according to the value if you can help me cuz I am not able to do this.

  9. alright , so i have a doubt…..
    int x cant include float variables but float variable can include int variables,
    how does the program understand that?
    i mean to say 38=38.00

  10. So if I do this:

    #include <iostream>

    using namespace std;

    void printNumber(int x){
        cout << "i am print an interger" << x << endl;
    }

    void printNumber(float x){
        cout << "now i am print a float" << x << endl;
    }

    int main()
    {
       int a = 54;
       int c = 24;
       float b = 32.4896;
       int x = 25;

       printNumber(a);
       printNumber(b);
       printNumber(c);
       printNumber(x);

    How does the program know how to reconcile the "X's"? I.e. why doesn't it associate x in the "void printNumber(int x)" with "int x" in the int main?

  11. Someone said this is called function overriding in Java. Overriding makes more sense than overloading. A noob would have an idea what a function override is than a function overload without knowing what they are ahead of time. C++ comes up with odd names

  12. why can we just write it like this? 

    void printNumber(float x, int x)
    {

    }

    and lastly why use void if we are expecting a result back by using this function ? i mean its going to cout something right? so it is going to do something use this and pass a result right ? so why use void? 

    and in all your tutorials you keep using the user puts in this or that but you go and write it in on the ide and then compile it thus giving you the result BUT IF the  user will input then it should be CIN and thats after you build a data type and a variable = to zero cuz we dont know what the user might type in , and then compile the code and NOW you chud say your fav line "the user will type in and thus run your code and cout the result

  13. bucky WHY do you keep saying user enters and then you go on to write on the parameter of COUT what the user chud be putting in VIN ???? dont complicate things by saying something but doing something else, use the functions NEVER say the user puts…….. and den go on to cout<< rather cin>> so that way it makes sense "cents" to everything thats been sum'up to this point i mean com'on this tu 28 trat us like we are keeping up not like we are still on tut 2 or something

Leave A Reply

Please enter your comment!
Please enter your name here