Click here to Skip to main content
15,892,161 members
Home / Discussions / C#
   

C#

 
GeneralRe: Update in C# using SQL Server Database. Pin
Agent__00713-May-15 20:43
professionalAgent__00713-May-15 20:43 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell13-May-15 20:50
Norris Chappell13-May-15 20:50 
NewsRe: Update in C# using SQL Server Database. Pin
Norris Chappell15-May-15 13:39
Norris Chappell15-May-15 13:39 
Questionhow work class scheduling system by C# Pin
Member 116782469-May-15 19:54
Member 116782469-May-15 19:54 
AnswerRe: how work class scheduling system by C# Pin
OriginalGriff9-May-15 19:58
mveOriginalGriff9-May-15 19:58 
AnswerRe: how work class scheduling system by C# Pin
Afzaal Ahmad Zeeshan10-May-15 10:33
professionalAfzaal Ahmad Zeeshan10-May-15 10:33 
QuestionMethod Overload Troubles? Pin
Marcel Cartier9-May-15 16:42
Marcel Cartier9-May-15 16:42 
AnswerRe: Method Overload Troubles? PinPopular
OriginalGriff9-May-15 19:57
mveOriginalGriff9-May-15 19:57 
The only declaration of Add3Numbers you have in that code is this:
C#
static int Add3Numbers(int One, int Two, int Three)
    {
        int Return = One + Two + Three;
        return Return;
    }
And you only use it twice, once in your Main method:
C#
int Sum = Add3Numbers(Input1, Input2, Input3);
And once in your GetThirdInputFromUser metyhod:
C#
Add3Numbers();
The first use is fine: the method you declare requires three integers as parameters (that is called it's Signature) and your provide three integer values when you call it.
But the second call is different - you don't supply any parameters at all! So the system looks for methods called Add3Numbers, and can only find one, which needs three integers, and says "No overload takes 0 parameters" (or similar).
It's a bit like applying for a passport: You need to supply a recent photo of yourself, a copy of your birth certificate, and a cheque for £72.50. If you supply all three "parameters" then teh passport issuing authority will send you a passport. If you don't supply any one of them, all you will get back is a rude letter!
The passport office only have a Signature that want's three parameters, they don't define a method signature than has none!

There is also the fun that it couldn't be executed anyway:
C#
if ((ThirdInput / 42 == 1) || (ThirdInput / 42 == 2))
    {
        return ThirdInput;
        Add3Numbers();
    }
The return on the line above is not conditional; it will always exit the method at that point so any code after that will get an error saying "unreachable code detected".

And don't worry about the bracket alignment: once you get a clean compile, you can hold CTRL and press K, then (still holding CTRL) press D - Visual Studio will reformat the document for you.

But there are quite a lot of things you want to sort out first...your loop in GetThirdInputFromUser is rather odd as well:
C#
while (ThirdRepeat) // Start of loop
    {
        if ((ThirdInput / 42 == 1) || (ThirdInput / 42 == 2))
            {
                return ThirdInput;
                Add3Numbers();
            }
            else
                {
                    ThirdRepeat = false;
                    Console.WriteLine("That number is not evenly divisble by 42. Please try again");
                    GetThirdInputFromUser();
    } while (ThirdRepeat); // End loop
That's not the right syntax for a while loop: you don't need the "extra" while at the bottom:
C#
while (ThirdRepeat)
    {
        if ((ThirdInput / 42 == 1) || (ThirdInput / 42 == 2))
            {
                return ThirdInput;
                Add3Numbers();
            }
            else
                {
                    ThirdRepeat = false;
                    Console.WriteLine("That number is not evenly divisble by 42. Please try again");
                    GetThirdInputFromUser();
    }
And let's be honest, that's not going to loop anyway because either you will use the return to exit, or you will set ThirdRepeat to false which will exit the loop anyway...
It all looks like "I panicked and wrote down anything" code instead of something you sat down and thought about - I'd suggest that you might be better off leaving this alone and starting from the beginning after thinking carefully about what you are trying to achieve.
The way I would do it is like this:
C#
static void Main(string[] args)
   {
   int even = GetEvenNumber();
   int odd = GetOddNumber();
   int divisibleBy42 = GetDivisibleNumber(42);
   Console.WriteLine("Even      : {0}\nOdd       : {1}\nDivisible : {2}", even, odd, divisibleBy42);
   }
private static int GetEvenNumber()
   {
   return -1;
   }
private static int GetOddNumber()
   {
   return -1;
   }
private static int GetDivisibleNumber(int divisor)
   {
   return -1;
   }
And then get each method in turn working before moving to the next.
I'd probably write a method that got a number from the user, and call it in each of those three then validate the number to see if it is acceptable...

Little hint on the last one - if you use the Modulus operator "%", you can check for divisibility very easily: if it returns 0, the number is exactly divisible...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

Questionwebbrowser auto tab click Pin
esancakdar8-May-15 2:17
esancakdar8-May-15 2:17 
AnswerRe: webbrowser auto tab click Pin
Dave Kreskowiak8-May-15 3:49
mveDave Kreskowiak8-May-15 3:49 
AnswerRe: webbrowser auto tab click Pin
Dr Gadgit10-May-15 4:29
Dr Gadgit10-May-15 4:29 
QuestionHow Do I Pin
Cianide8-May-15 2:00
Cianide8-May-15 2:00 
SuggestionRe: How Do I Pin
ZurdoDev8-May-15 2:20
professionalZurdoDev8-May-15 2:20 
GeneralRe: How Do I Pin
Cianide8-May-15 3:14
Cianide8-May-15 3:14 
AnswerRe: How Do I PinPopular
Pete O'Hanlon8-May-15 2:24
mvePete O'Hanlon8-May-15 2:24 
GeneralRe: How Do I Pin
Cianide8-May-15 2:35
Cianide8-May-15 2:35 
GeneralRe: How Do I Pin
Pete O'Hanlon8-May-15 2:37
mvePete O'Hanlon8-May-15 2:37 
GeneralRe: How Do I Pin
Cianide8-May-15 3:16
Cianide8-May-15 3:16 
GeneralRe: How Do I Pin
Mycroft Holmes8-May-15 13:52
professionalMycroft Holmes8-May-15 13:52 
GeneralRe: How Do I Pin
ZurdoDev8-May-15 3:16
professionalZurdoDev8-May-15 3:16 
Questionreceived data by UDP client Pin
hasan hadi7-May-15 21:43
hasan hadi7-May-15 21:43 
AnswerRe: received data by UDP client Pin
F-ES Sitecore9-May-15 2:25
professionalF-ES Sitecore9-May-15 2:25 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 3:38
hasan hadi9-May-15 3:38 
GeneralRe: received data by UDP client Pin
F-ES Sitecore9-May-15 7:05
professionalF-ES Sitecore9-May-15 7:05 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 7:42
hasan hadi9-May-15 7:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.