Free Friday 8/28/26

Today I converted 5 python problems into c++. If statements were the focus. With the problems focusing on temperature, grades, positive and negative numbers, and so on.

    //problem 5
    float numb1;
    float numb2;
    string oper;

    cout << "Enter the first number: ";
    cin >> numb1;
    cout << "Enter the another number: ";
    cin >> numb2;
    cout << "What operation: ";
    cin >> oper;
    if (oper == "+") {
        cout << "Answer: " << numb1 + numb2;
    }
    else if (oper == "-") {
        cout << "Answer: " << numb1 - numb2;
    }
    else if (oper == "/") {
        cout << "Answer: " << numb1 / numb2;
    }
    else if (oper == "*") {
        cout << "Answer: " << numb1 * numb2;
    }
    else {
        cout << "Not an operation!";
    }

This helped me make sense of if / else statements in c++.

Leave a Reply

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