Basic Calculator Doubt

#include
using namespace std;

int main()
{
char ch;
float num1, num2;
cin >> ch;
cin >> num1 >> num2;

if(ch=='+')
{
    
        cout << num1+num2;
        
}
else if(ch=='-'){
    
        cout << num1-num2;
        
}
else if(ch=='*'){
    
        cout << num1*num2;
        
}
else if(ch=='/'){
    
        cout << num1/num2;
        
}	
    else if(ch=='X' || ch=='x'){
		break;
	}
	
    else {
        
        cout << "Invalid operation.Try again"<<endl;
       
	}


return 0;

}

In line number 37 I’m getting error as “break statement not within loop or switch”. Why is this happening?

The break command is used for exiting loops, you are not in a loop you are just in an else if statement, you have nothing to break from. The code flow executes normally after passing that else statement. If you want to exit the program in that else statement you could do something like return 0;

After writing return 0 in place of break, I’m getting only 2 as output.

add a loop like:
if(ch=='%' or ch=='/' or ch=='*' or ch=='+' or ch=='-'){
coz you have to keep on going unless u see x/X add a break there
to make a loop run indefinitely use while(true)