char* array{};
string digit4;
cout << "Enter a 4 digit-integer : " << endl;
cin >> digit4;
cout << "The 4 digit-integer you have entered is : " << digit4 << endl;
array = &digit4[0];
cout << "Digit 1 is : " << array[0] << endl;
int digit1 = (array[0] + 7) % 10;
cout << digit1 << endl;
return
I tried to convert a string to an array and use the first digit of array[0]
to a formula of ( array[0] + 7 ) % 10
. If I input 1234
, ( 1 + 7 ) % 10
should be 8 but I'm getting 6 instead of 8. Any help would be great. Thank you for reading.