Variable Problem



  • moin moin
    ich habe ein problem...
    kann mir vieleicht jemand erklären, wieso man bei

    33 * 2 + (99 - (VariableZwei + 5 * VariableDrei))
    

    auf 118 kommt?

    #include <iostream>
    
    using namespace std;
    
    int Variable; 
    long VariableZwei = 22;
    short VariableDrei = 5;
    
    int main(void)
    {
       cout << "V                         : " << Variable;
       cout << "\nVZ                        : " << VariableZwei;
       cout << "\nVD                        : " << VariableDrei << '\n';
    
       Variable = 33 * 2 + (99 - (VariableZwei + 5 * VariableDrei)); // 118
       cout << "\n\nV = 33*2+(99-(VZ+5*VD)) : " << Variable;
    
       cin  >> Variable;
    
       return 0;
    }
    

    sry, aber bin neu in c++
    wär schön wenn ihr mir helft
    mfg exe-cute



  • exe-cute schrieb:

    moin moin
    ich habe ein problem...
    kann mir vieleicht jemand erklären, wieso man bei

    33 * 2 + (99 - (VariableZwei + 5 * VariableDrei))
    

    auf 118 kommt?

    Weil die allgemeinen Regeln der Mathematik angewandt werden, in dem Fall Klammerung und Punkt vor Strich?

    5 * VariableDrei = 25
    VariableZwei + VariableDrei = 47
    99 - 47 = 52
    33*2 + 52 = 118

    Was hättest du denn erwartet?



  • Ist doch korrekt:

    VariableZwei + 5 * VariableDrei = 22 + 5 * 5 = 22 + 25 = 47
    99 - 47 = 52
    33 * 2 + 52 = 66 + 52 = 118

    Punkt vor Strich Regel halt! 😉

    Edit: zu spät 🙂



  • 33 * 2 + (99 - (VariableZwei + 5 * VariableDrei))
    

    332+(99(VariableZwei+5VariableDrei))\Rightarrow 33 \cdot 2 + (99 - (VariableZwei + 5 \cdot VariableDrei))
    Inhalt von VariableZwei ist 22
    Inhalt von VariableDrei ist 5

    332+(99(22+55))\Rightarrow 33 \cdot 2 + (99 - (22 + 5 * 5))
    =332+(99(22+25))= 33 \cdot 2 + (99 - (22 + 25))
    =332+(99(47))= 33 \cdot 2 + (99 - (47))
    =66+52= 66 + 52
    =118= 118

    Wo ist das Problem 😕

    Edit: Auch zu spät 😃



  • der code ist zwar mist ... aber nja ist doch einfache Mathematik.

    33 * 2 + (99 - (22 + 5 * 5)) = 118
    <=> 66 + (99 - (22 + 25)) = 118
    <=> 66 + 99 - 47 = 118
    <=> 66 + 52 = 118
    <=> 118 = 118
    

    nja und zum Code

    #include <iostream>
    
    int main()
    {
        int num_one = 0;
        int num_two = 22;
        int num_tree = 5;
        std::cout << "Variable \"num_one\": " << num_one << std::endl;
        std::cout << "Variable \"num_two\": " << num_two << std::endl;
        std::cout << "Variable \"num_tree\": " << num_tree << std::endl;
        std::cout << "num_one = 33 * 2 + (99 - (num_two + 5 * num_tree))" << std::endl;
        num_one = 33 * 2 + (99 - (num_two + 5 * num_tree));
        std::cout << "=> num_one = " << num_one << std::endl;
        std::cin.get();
    }
    

    🙂



  • Tooo late 😮 😃



  • oO
    sry leute das ich noch keine ahnung damit hab ^^
    jetzt ist mir alles kalrer^^
    ich bin auch blöd hab die punkt vor strich rechnung nicht beachtet
    danke 🙂
    und echt schnell die antwort 🙂
    thx
    mfg exe-cute


Anmelden zum Antworten