0

Here is my sample code

int sinNum;
string sin;

Console.Write("\nPlease enter a SIN Number: ");
sin = Console.ReadLine();

if (isInt && sin.Length == 9)
{
    int secondDigit = (sin / 10000000) % 10;

This int seconddigit is where I am get an error:

Operator '/' cannot be applied to operands of type 'string' and 'int'

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Grace
  • 27
  • 6

1 Answers1

1

You are likely going to want to add something like

int parsedValue;
isInt = int.TryParse(sin, out parsedValue);

You will then be able to do

int secondDigit = (parsedValue/ 10000000) % 10;

The reason that is failing is because you can't do division on a string. You need to do some sort of conversion to a numeric data type that implements the / operator.

Just as an added FYI the % (mod) operator doesn't return the second digit. Instead it returns the remainder from doing a integer based division operation.

brianfeucht
  • 774
  • 8
  • 21