C++ Pogreška u kodu

poruka: 3
|
čitano: 1.351
|
moderatori: XXX-Man, vincimus
1
+/- sve poruke
ravni prikaz
starije poruke gore
10 godina
neaktivan
offline
C++ Kalkulator (POTREBAN POPRAVAK)

Ovo je kod, može li mi netko pomoći i ispraviti ga?

 

#include <iostream>

using namespace std;

int main()
{
    int a;
    int b;
    string operation;

    cout << "Enter +, -, * or /" << endl;
    cin >> operation;
    cout << "Enter a number" << endl;
    cin >> a;
    cout << "Enter another number" << endl;
    cin >> b;

    switch(operation) {
        case "+":
            cout << a + b << endl;
            break;
        case "-":
            if(a > b) {
                cout << a - b << endl;
            } else {
                cout << b - a << endl;
            }
            break;
        case "*":
            cout << a * b << endl;
            break;
        case "/":
            if(a > b) {
                cout << a / b << endl;
            } else {
                cout << b / a << endl;
            }
            break;
        }

    return 0;
}

Poruka je uređivana zadnji put sri 17.6.2015 22:33 (H3X0FK1N65).
 
0 0 hvala 0
15 godina
offline
Re: C++ Kalkulator (POTREBAN POPRAVAK)
Nemoš switchat stringove u cpp-u.

Napravi sa setom if-elsova
One ring to bring them all and in the darkness bind them
16 godina
neaktivan
offline
C++ Pogreška u kodu

 Ili samo promijenis u char

char operation

 

i onda u jednostruke navodnike u swtichu '+' '*' '-' ...

 
0 0 hvala 1
1
Nova poruka
E-mail:
Lozinka:
 
vrh stranice