CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Nov 2018
    Posts
    1

    I'm bad help me why doesn't this work

    Code:
    #include <iostream>
    using namespace std;
    
    int main() { 
        int x;
        int a, b;
    
        cout << "welcome to the calculator" << endl;
        cout << "enter 1 for division, 2 for multiplication, 3 for addition and 4 for subtraction" << endl;
        cin >> x;
    
        int sum;
    
        if (x == 1) {
            sum = a / b;
        }
    
        if (x == 2) {
            sum = a * b;
        }
    
        if (x == 3) {
            sum = a + b;
        }
    
        if (x == 4) {
            sum = a - b;
        }
    
        cout << "enter a number" << endl;
        cin >> a;
    
        cout << "one more please" << endl;
        cin >> b;
    
        cout << "and your answer is!" << endl; 
        cout << sum;
    
        return 0;
    }
    It just says - 37 or 0. I want it to be able to calculate stuff
    Last edited by 2kaud; November 19th, 2018 at 10:13 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured