#Beginner C++ programmer need help fixing bugs

34 messages · Page 1 of 1 (latest)

brave robin
#

I'm a beginner c++ programmer and i'm currently making a calculator and got this bug i need some help fixing it

sacred ruinBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

brave robin
#
#include <iostream>
#include <cmath>
int main()
{
    char op;
    int num1;
    int num2;
    int result;

    std::cout << "Enter operator:";
    std::cin >> op;

    std::cout << "Enter num1:";
    std::cin >> num1;

    std::cout << "Enter num2:";
    std::cin << num2;

    switch(op){
        case "+":
            result = num1 + num2;
        case "-":
            result = num1 - num2;
        case "*":
            result = num1 * num2;
        case "/":
            result = num1 / num2;
    }
    std::cout << result;
    return 0;
}
#

here's the code

#

the errors has lots of lines that i cant capture all of them in a pic

humble flax
#
std::cin >> num1;
std::cin << num2;
brave robin
#

oh sh

#

my bad srry

#

i cant remember the >> and <<

humble flax
#

It happens 😄

oak tusk
#

Why does a beginner need to see all that crap because they mixed up << and >>?

brave robin
#

i always mistaken cin and cout

humble flax
#

cout << x - x is printed TO cout
cin >> x - x is read FROM cin to x

brave robin
#

that helps

#

tysm

humble flax
brave robin
#

uhh

#

after fixing that

#

i still got some bugs ;-;

humble flax
#

Show the errors

brave robin
oak tusk
humble flax
#

case '+'

brave robin
#

wha

#

why

humble flax
#

"+" is a string, possibly with multiple or 0 characters. '+' is a single character

#

Also switch is dumb and can only switch on integers (which includes single characters)

#

And also you need break; at the end of each case branch

brave robin
#

!solved

sacred ruinBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity