-4

I am trying to create a small application that takes an input from the user (should be the month), and takes the first character and adds one, takes the second and adds two, and takes the third, and adds three.

I have got it working without using an extra method and just repeating myself, but wanted to try and implement one.

I am receiving the error "Program.MonthInteger(int, int)': not all code paths return a value" with my method, however, I am not sure why. It is showing a red error line under the declaration of the method.

My code is below, could someone give me a hand, and let me know where I am going wrong, please?

Thank you.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PasswordCalculator
{
    class Program
    {
        static void Main(string[] args)
        {
            char monthOne = MonthInteger(0, 1);
            char monthTwo = MonthInteger(1, 2);
            char monthThree = MonthInteger(2, 3);

            Console.WriteLine("Your Password is {0}{1}{2}", monthOne, monthTwo, 
monthThree);
        }

        static char MonthInteger(int stringChar, int addHowLetter)
        {
            int monthLetterInt;
            char monthLetter;
            string month;

            Console.WriteLine("What month would you like the password for?");
            month = Console.ReadLine();

            monthLetterInt = month[stringChar] + addHowLetter;
            monthLetter = Convert.ToChar(monthLetterInt);
        }
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
MBH999
  • 3
  • 3

2 Answers2

2

You are missing your return statement. You need to add return monthLetter; as the last line of your month integer method

David Watts
  • 2,249
  • 22
  • 33
0

MonthInteger method doesnt include any return statement

Curious
  • 474
  • 1
  • 8
  • 25