can you help me to solve errors in this code?

There are several issues in your code,

  1. In C++ = stands for assignment to check value equivalency you have to use ==
    if (choose = 1, 2, 3){
       ...
    // this doesn't work in C/C++
    // change it into 
    if (choose == 1 || choose == 2 || choose == 3)
  1. When you have more than one line of code under a conditional (if/else or loops for/while) you will need to explicitly block them inside curly braces. So that changes if first if block into this

     if (choose == 1 || choose == 2 || choose == 3){
         cout << "Insert the first value: " << endl;
         cin >> first;
         cout << "Insert the second value: " << endl;
         cin >> second;
         ...
    
  2. Same goes for the nested if condition.

  3. Also there’s no reason to take input for start.

  4. If you fix all the errors you should get a code like this ->

    //CALCULATOR
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int start;
        int choose;
    
        int first;
        int second;
        int unic;
    
        int result;
    
        cout << "CALCULATOR (2 values)" << endl;
        cout << "Click a botton to continue: " << endl;
        // cin >> start;
        cout << "Write: " << endl;
        cout << "- '1' for sum" << endl;
        cout << "- '2' for subtraction" << endl;
        cout << "- '3' for moltiplication" << endl;
        cout << "- '4' for power of 2" << endl;
    
        cout << "Your answer: " << endl;
        cin >> choose;
        cout << "________________________" << endl;
    
        if (choose == 1 || choose == 2 || choose == 3){
            cout << "Insert the first value: " << endl;
            cin >> first;
            cout << "Insert the second value: " << endl;
            cin >> second;
    
            if (choose == 1)
                result = first + second;
    
            if (choose == 2)
                result = first + second;
    
            if (choose == 3)
                result = first * second;
        }
    
        if (choose == 4){
            cout << "Insert the value: " << endl;
            cin >> unic;
            result = unic * unic;
        }
    
        cout << "Your result is: " << result << endl;
    }

Footnote: Please use the given code as reference and try to understand the basics carefully. It is importat you do that.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top