Click here to Skip to main content
15,912,329 members
Home / Discussions / C#
   

C#

 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell13-May-15 20:30
Norris Chappell13-May-15 20:30 
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 
Hello,

Before starting college two weeks ago I didn't even know what C# was; I had never worked with codes other than HTML customization on Tumblr and Wordpress.com.

An exercise I have for school is to create a program that asks for three numbers, the first an even number, the second an odd number, and the third a number that can be evenly divided by 42. (The exercise isn't graded.) We're practicing methods, and I feel like I have the entire program right, except for this one method that I can't seem to get to work, the Add3Numbers method.

What am I doing wrong? Confused | :confused:

The Add3Numbers() in bold at the end is the problem. The red line disappears if I insert random numbers – like Add3Numbers(1, 2, 3) – but the program still doesn't run? Without the numbers I get the error "method overload. Method has 0 arguments."

Sorry if some of the {} are out of position. I tried to make them in order, but, I did copy and paste this…

C#
class Program

{

    static void Main(string[] args)

    {

        // Declare variables at start

        int Input1 = 0;
        
        int Input2 = 0;
        
        int Input3 = 0;
        
        // Call methods
        
        Input1 = GetFirstInPutFromUser();
        
        Input2 = GetSecondInputFromUser();
        
        Input3 = GetThirdInputFromUser();
        
        int Sum = Add3Numbers(Input1, Input2, Input3);
        
        Console.WriteLine("The sum is " + Sum);
        
        Console.ReadLine();

    }

// First method

static int GetFirstInPutFromUser()

{

        Console.WriteLine("Please enter an even number");
        
        int FirstInput = Convert.ToInt32(Console.ReadLine());
        
        bool FirstRepeat = true;
        
        // Start loop

    while (FirstRepeat)

    {

         if (FirstInput % 2 == 0)

            {

                return FirstInput;
                
                GetSecondInputFromUser();

            }

        else

            {

                FirstRepeat = false;
                
                Console.WriteLine("That number is not an even number. Please try again.");
                
                GetFirstInPutFromUser();

            }

    } while (FirstRepeat); // End loop

}

// Second method

static int GetSecondInputFromUser()

{

        Console.WriteLine("Please enter an odd number");

        int SecondInput = Convert.ToInt32(Console.ReadLine());
        
        bool SecondRepeat = true;
        
        // Start of loop

        while (SecondRepeat)

            {

                if (SecondInput % 2 >= 1)

                    {

                        return SecondInput;
                        
                        GetThirdInputFromUser();

                    }

                    else

                    {

                        SecondRepeat = false;

                        Console.WriteLine("That is not an odd number. Please try again");
                        
                        GetSecondInputFromUser();

                    }

            } while (SecondRepeat); // End of loop

}

// Third method

static int GetThirdInputFromUser()

{

        Console.WriteLine("Please enter a number evenly divisble by 42");
        
        int ThirdInput = Convert.ToInt32(Console.ReadLine());
        
        bool ThirdRepeat = true;
        
        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



}

// Fourth method

static int Add3Numbers(int One, int Two, int Three)

    {

        int Return = One + Two + Three;

        return Return;

    }

}

}

AnswerRe: Method Overload Troubles? Pin
OriginalGriff9-May-15 19:57
mveOriginalGriff9-May-15 19:57 
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 Pin
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 

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.