CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2014
    Posts
    3

    Need some help with my program.

    Hi all,

    I've read the FAQ on homework questions but I am really stuck at the moment and to be honest I have no idea what I am doing. The task at hand is as follows.

    "An Albanian social security number has a sequence of digits
    followed by a letter. This 'check' letter is determined from
    the values of the digits and is used to ensure that the numbers
    are correct. Write a program that, when given a ten-digit
    number and letter as input, calculates a unique 'check'
    character corresponding to the given number according to the
    following rules:

    Add the five pairs of digits contained in the number
    Take the remainder of dividing the result by 26
    Select the letter in that position of the alphabet, starting
    with 'A' in position 0, 'B' in position 1, and so on.

    For example, if the input is 1122334455J, the program should
    calculate (11 + 22 + 33 + 44 + 55) % 26 giving 9, and so 'J'
    is the 'check' character. This means that the social security
    number quoted is correct. If the input was 1122334455M, your
    program should detect that the check letter is incorrect,
    and therefore that this social security number is false."

    This is what I've got so far.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace CourseWork
    {
        class Program
        {
            static void Main(string[] args)
            {
                string socialNumber;
                char check;
     
    
                Console.WriteLine("please Write your social number without the letter."); //asks user to input social number without letter
                string first = Console.ReadLine();
     
                socialNumber = first.Substring(0, 10);
                check = first[first.Length-1];
                Console.WriteLine(check+socialNumber);
                
                int sum = 0;
                for (int i =0; i < socialNumber.Length-1; i++)
                {
                    sum += Int32.Parse(socialNumber[i].ToString());
                }
     
                int remainder = sum % 26;
     
    
                if (remainder == check)
                {
                    Console.WriteLine("This is a correct number.. the check is {0} \\n the remainder is {1}", check, remainder);
                }
     
                else
                {
                    Console.WriteLine("Please write your check letter.");
                }
                Console.WriteLine(sum);
                Console.ReadLine();
     
            }
        }
    }
    So far I've asked the end user to input their social security number without the check letter.

    What I can't get my head around is the division doesn't work and always returns the number 25 or it just closes the program. I don't know where to go from here >_< can somebody help me?

    Could somebody possibly help me correct and finish the code for me with comments on within the program to whats been done to it?

    Many thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Need some help with my program.

    Press F8 to STEP thru the code line by line, and then examine the value of this:

    Code:
    Int32.Parse(socialNumber[i].ToString());

    It is probably not what you expect.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Need some help with my program.

    When you extract out the number in the sum += line, you need to extract out two characters at a time (and increment the index of he loop by 2).

  4. #4
    Join Date
    Jan 2014
    Posts
    3

    Re: Need some help with my program.

    Hi, could you possible delete this thread as I have solved the program by myself. Thank you

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Need some help with my program.

    Quote Originally Posted by harryc1127 View Post
    Hi, could you possible delete this thread as I have solved the program by myself. Thank you
    Instead of deleting the thread, how about you taking a few minutes to post your solution or at least state how you fixed it? That way, any folks searching for similar can find it (and the time spent replying to you isn't wasted).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured