私の質問は、ユーザーが私のプログラムに入力した SIN を検証する方法です。IF が有効かどうかを印刷するように見えません。が無効である場合、プログラムはもう一度 sin を要求しますが、もう一度無効な場合はプログラムを終了する必要があります。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sinValidator
{
class Program
{
static void Main(string[] args)
{
//Variables
Int32 numbers1, numbers2, numbers3, numbers4, numbers5, numbers6, numbers7, numbers8, numbers9;
Int32 sin;
bool valid;
Int32 sum;
Int32 product;
double test;
{
// Prompt for user input
Console.WriteLine("\n Enter SIN: ");
sin = Int32.Parse(Console.ReadLine());
// spliting the SIN into 9 seperate digits in different variables, and then printing them.
Console.WriteLine("The first digit is {0}", numbers1 = (sin / 100000000));
Console.WriteLine("The second digit is {0}", numbers2 = (sin % 100000000 / 10000000));
Console.WriteLine("The third digit is {0}", numbers3 = (sin % 10000000 / 1000000));
Console.WriteLine("The fifth digit is {0}", numbers4 = (sin % 1000000 / 100000));
Console.WriteLine("The sixth digit is {0}", numbers5 = (sin % 100000 / 10000));
Console.WriteLine("The seventh digit is {0}", numbers6 =(sin % 10000 / 1000));
Console.WriteLine("The eighth digit is {0}", numbers7 = (sin % 1000 / 100));
Console.WriteLine("The ninth digit is {0}", numbers8 =(sin % 100 / 10));
Console.WriteLine("The tenth digit is {0}", numbers9 = (sin % 10));
// Beginning of validation
//obtaining product of the sin using provided multipliers
product = ((numbers1 * 1) + (numbers2 * 2) + (numbers3 * 1) + (numbers4 * 2) + (numbers5 * 1) + (numbers6 * 2) + (numbers7 * 1) + (numbers8 * 2));
Console.WriteLine("The product {0}", product);
// using div and mod to get numbers for the sum of digits
sum = (((numbers1 * 1)+ (numbers2 * 2) % 10) +((numbers2 * 2) / 10) + (numbers3 * 1) + ((numbers4 * 2)%10) + ((numbers4 * 2)/10) + (numbers5 * 1) + ((numbers6 * 2)%10)+((numbers6 * 2)/10) + (numbers7 * 1) + ((numbers8 * 2)%10) + ((numbers8 * 2)/10));
//Console.WriteLine("sum = {0}", sum);
//Test to see if sum % 10 subtracted by 10 will give final digit
test = (10 -(sum % 10));
// Console.WriteLine("{0}", test);
test = double.Parse(Console.ReadLine());
Console.ReadLine();
//Display the results
//Console.WriteLine("first = {0}, second = {1}, third = {2}, fourth = {3}, fifth = {4}, sixth = {5}, seventh = {6}, eighth = {7}, ninth = {8}",
//numbers1, numbers2, numbers3, numbers4, numbers5, numbers6, numbers7, numbers8, numbers9);
valid = false;
if (test > numbers9)
{
if (test == numbers9)
valid = true;
}
Console.WriteLine("{0}", valid);
valid = false;
if (numbers9 > test && test < numbers9)
{
valid = true;
}
Console.WriteLine("{0}", valid);
Console.ReadLine();
}
Console.ReadLine();
}
}
}