Not showing proper output

I wrote a code to check if the serial monitor is providing a numerical digit or alphabet. Then, if it's nuemerical digit, print the digit or if it is alphabet then print the assigned digit assigned to it. I'm unable to understand where I'm doing things wrong.

void setup() {
  
  Serial.begin(9600);
  
  }

void loop(){

if (Serial.available() > 0) {
    int thisChar = Serial.read();
   if (isDigit(thisChar)) {
      total = thisChar;   
      Serial.println(total);
    }

   if (isAlpha(thisChar)) {
      Serial.println("it's alphabetic");
      
      if(data=='F')
  {
    OnMin = 16;
    Serial.print("15");
  }
  else if(data=='B')
{
  OnHour = 20;
  Serial.print("20");
}
    }
    
    while (Serial.available() > 0) {
       Serial.read();
}
  }

total = thisChar - '0'; ?

The posted code will not compile
Did you forget to post the code/declarations before setup() in the code or don't you have any ?

UKHeliBob:
The posted code will not compile
Did you forget to post the code/declarations before setup() in the code or don't you have any ?

I'm sorry I forgot to copy the declaration part. This was the code :

int total,OnHour,OnMin,data;
void setup() {
 
  Serial.begin(9600);
 
  }

void loop(){

if (Serial.available() > 0) {
    int thisChar = Serial.read();
   if (isDigit(thisChar)) {
      total = thisChar - '0';   
      Serial.println(total);
    }

   if (isAlpha(thisChar)) {
      Serial.println("it's alphabetic");
     
      if(data=='F')
  {
    OnMin = 16;
    Serial.print("15");
  }
  else if(data=='B')
{
  OnHour = 20;
  Serial.print("20");
}
    }
   
    while (Serial.available() > 0) {
       Serial.read();
}
}
}

I see you’ve made changes.
And . . ?

TheMemberFormerlyKnownAsAWOL:
I see you’ve made changes.
And . . ?

Before I made changes, when I sent 10, the serial monitor printed 49 and 53 in different lines. Now, after making changes according to your suggestions, when I sent 10, the serial monitor printed 1 and 0 in different lines. I also tried sending 55, but the outcome was the same. Can’t I get proper 10 printed? As I’m sending 10 as input?

sabit068:
As I’m sending 10 as input?

But you’re not; you’re sending ‘1’ followed by ‘0’.

This has been covered here so many times.
Take a pinch of ASCII decoding ( - ‘0’), and add a dash of primary school number base arithmetic.

TheMemberFormerlyKnownAsAWOL:
But you're not; you're sending '1' followed by '0'.

This has been covered here so many times.
Take a pinch of ASCII decoding ( - '0'), and add a dash of primary school number base arithmetic.

Sorry I didn't get you. Can you please explain more? Is there any example?

Think of the number 768.

That’s 7 x 102 plus 6 x 101 plus 8 x 100

For programming, the only tricky bit is deciding where the number starts, and where it ends.

TheMemberFormerlyKnownAsAWOL:
For programming, the only tricky bit is deciding where the number starts, and where it ends.

Is there any example?

Some use the first numeric character as the start of the number, and the carriage return character (or any other non- numeric character) as the end of the number.

It is simple:

When you have an integer 2 and it represents the ‘tens’ in your number you multiply by 10
When it represents the ‘hundreds’ you multiply by 10 twice

So 23 is integer 2 times 10 and integer 3
234 is integer 2 times 10 times 10 and integer 3 times 10 and integer 4

Depending on how variable the places of your number are, or how you reference it, there are various ways you can determine the factor

Let’s suppose that you enter 456 and send it to the Arduino
What you get is ‘4’ then ‘5’ then ‘6’ as individual characters

You can turn them into real digits rather than characters representing digits by subtracting 48 from them (see ASCII codes) so now you have 4 then 5 then 6

Multiply the 4 by 100 = 400
Multiply the 5 by 10 = 50
Leave the 6 alone = 6
Sum the 3 results = 456

In a program you would probably do it slightly differently

sum = 0
start of loop
  multiply sum by 10
  get a character and convert to a digit
  add the digit to sum
  keep going until you have all of the digits
end of loop

As previously noted, the main trick is to identify the start and end of the number