Click here to Skip to main content
15,030,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm just learning how to use C# and have been faced with this error as part of an assignment for my class. Unfortunately, I'm code illiterate at the moment, so please be patient with me. Based on the code below, I know that I'm compiling something wrong, but I don't understand what I'm doing wrong and keep getting a CS1520 "Method must have a return type" error and can't figure out why.

Edit: Adding void to static void Main() produces a CS0017 error of "More than one entry point defined". Yet again, I don't understand what this means, or what I should fix.

What I have tried:

using System;
using System.Linq;

class Program
{
    static Main()
    {
        int number1, number2, number3;
        Console.Write("Enter an integer score");
        number1 = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter an integer score");
        number2 = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter an integer score");
        number3 = Convert.ToInt32(Console.ReadLine());

        int result = (number1 + number2 + number3) % 3;
        Console.WriteLine("The average of {0}, {1}, {2} is: {3}",
        number1, number2, number3, result);
    }
}
Posted
Updated 14-Mar-18 1:48am
v2
Comments
George Swan 14-Mar-18 4:33am
   
Solution 1 is why you are getting the error but there is another error. Your calculation of the average is incorrect. You are calculating the modulus, you may also like to consider returning a double in order to get a more precise result.
Richard Deeming 15-Mar-18 15:53pm
   
"More than one entry point defined" means you have more than one Main method in your project.

You'll sometimes also see it if you create a WPF application and try to create a Main method.
Tryptyk 15-Mar-18 16:12pm
   
Had some errors when setting up an account/posting. I'm not certain how to remove one or the other, tbh.

You need a return type on every method in C#. Change your method prototype to this

static void main(string[] args)
   
v2
Comments
CPallini 14-Mar-18 6:22am
   
5.
John gave you the solution to the compilation problem.
Please note you have also a logical error:
Quote:
int result = (number1 + number2 + number3) % 3;
That's not compute the average of the three integers. You should write instead:
double avg = (number1 + number2 + number3) / 3.0;
   
This is intended to be very friendly advice!

The sooner you get into looking up and solving your own errors the better. Even more so, now, in the beginning. It should become beyond habit - a reflex.

It offers the possibility of helping you learn what you're doing faster. Like in the days of paper dictionaries. You could just look up the word you wanted - but you could also look at the words before and after it, as well - out of curiosity.

In the above, you really need to learn more about "return types" as they are absolutely deadly important in all typed computer languages.

Really - get into the lookup and then look beyond. For computer programming and everything else. It's a part of the route out of a lifetime of mediocrity that follows doing just the bare minimum.
   
Comments
Tryptyk 14-Mar-18 8:03am
   
You're right, of course, and I appreciate the advice. My main issue at the moment is a fundamental lack of understanding, both what particular errors mean and what the solutions mean too. For this kind of stuff, I really have to get in and use it and make mistakes before I'll understand, and unfortunately for me, that means lots of hair-pulling like earlier.

I don't particularly like just asking for answers, for the reasons you mentioned; I got frustrated at dealing with a problem that I couldn't understand at the moment.
W Balboos, GHB 14-Mar-18 8:11am
   
Think of it as an assault on castle. You have powerful allies, like google or even bing - especially if you have an error number or cut/paste the exact error message.

Like programming, itself, it's really always made of a lot of small pieces. Even the failures often end up helpful.

That being said, it depends upon where your strengths lie. You'll find many programmer on this site more knowledgeable than I. My strengths are in (very rapid) problems solving (and clever retorts). No compartmentalization of knowledge. Your assets will likely be different. Your contribution to countless gestalts.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900