in

Adding and substracting in C++


I am new to C++. Can someone tell me what is wrong with this code?

#include <iostream>

using namespace std;

int main(){

int number_of_operations;
string operation;
int x(0);

cin >> number_of_operations;

for(int i(1); i<=number_of_operations; ++i){
    cin >> operation;
    for(string::size_type j(0); j < operation.length(); j++){
        if(operation[j]==x){
            continue;
            }else if(operation[j]=='+'){
                x+=1;
                break;
                }else if(operation[j]=='-'){
                    x-=1;
                    break;
                    }
        }
    }

cout << x;
        
return 0;
}

Each input line is of the form x++, ++x, –x, x– and the code is suppose to add 1 to x if the input is ++x or x++ and substract 1 from x otherwise. When the input is over 44 lines, all of them with ++x or x– the output is 43 (which is wrong), but if all the input lines are –x or x– the output is correct.



Source: https://stackoverflow.com/questions/70716528/adding-and-substracting-in-c

A rough template to give you a starting point for your API

My Image is not rendering despite no errors JavaFx