Coffeehouse Thread

7 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Need Console Program help

Back to Forum: Coffeehouse
  • User profile image
    beadroux

    I have a C# class and need help. I don't need the work complete. Just some help getting this going. This is a console program. Any help would be appreciated. Here is what I have so far:

    static void Main(string[] args)
            {
                string dayInput;
                int inputStartTime;
                int inputEndTime;

                string _day = GetDay(dayInput);
                int _sTime = GetStartTime(inputStartTime);
                GetEndTime(inputEndTime);
                GetLength(inputStartTime, inputEndTime);
                ComputeRate(dayInput, inputStartTime, inputEndTime, length);

                Console.Read();
            }

            static string GetDay(string _day)

              {
                //string _day;
                                       
               Console.WriteLine("Please Provide the Day of the Week - ex. Mo Tu We Th Fr Sa Su");
               string dayInput = Console.ReadLine();
               dayInput = _day;
               dayInput = dayInput.ToLower();
                
                Console.Clear();
              }       
            
            
            static int GetStartTime(int _sTime)
            {
                //int _sTime;
                //string inputStartTime;

                Console.WriteLine("Enter the Start Time of Your Call in Military Time - ex. 1:30 pm = 1330");
                string input = Console.ReadLine();
                int inputStartTime = int.Parse(input);
                int result = GetStartTime (inputStartTime);
                Console.WriteLine(result);
                

                Console.Clear();
            
            }
            
            static int GetEndTime(int _eTime)
            {
                  //int _eTime;
                  //string inputEndTime;

                  Console.WriteLine("Enter the End Time of Your Call in Military Time - ex. 1:30 pm = 1330");
                  string input = Console. ReadLine();
                  int inputGetEndTime = int.Parse(input);
                  int result = GetEndTime (inputGetEndTime);
                  Console.WriteLine(result);

                Console.Clear();
            
            }
            
            static int GetLength(int _sTime, int _eTime)
            {
            int sModTime = _sTime % 100;
            int eModTime = _eTime % 100;
            int sHour = (_sTime – sModTime) / 100;
            int eHour = (_eTime – eModTime) / 100;
            int differenceHours = eHour – sHour;
            int differenceMinutes = eModTime – sModTime;
            int length = (differenceHours * 60) + differenceMinutes;
            return length;
               
            }
            
            static int ComputeRate(string _day, int _sTime, int _eTime, int _length)
            {
                double rate1 = .30;
                double rate2 = .15;
                double rate3 = .10;
                //double _length;
                //double total1;
             
         
                 if (_day == mo, tu, we, th, fr && _sTime <= 700 && _sTime >=2100);
                int total1 = double.Parse();
                _length = double.Parse();
                //rate1 = int.Parse(rate);
                total1 = _length * rate1;
                                
                Console.WriteLine("Your call cost " + total1);

            }
            
            static void DisplayErrorMessage()
            {
            //write code here

            }

  • User profile image
    evildictait​or

    Maybe you should ask a question rather than just posting some code and expecting people here to guess what it is that you want them to do with it.

  • User profile image
    AndyC

    I think you need to go back to day 1 and re-read all your notes on assignment and how it works. Once you are confident you understand that, read your notes about how values are passed in and out of methods.

    With those two things clear in your mind, you should be able to identify why your code doesn't work.

  • User profile image
    Michael Butler

    Ugh. underscores as parameter prefixes. never seen that before. ugly as sin.

    Might I suggest you look at DateTime and TimeSpan classes as an alternative.

    I'd also watch out for those semi-colons on the end of if statements

  • User profile image
    spivonious

    Is it a pass by reference problem?

    And please rethink your naming scheme. Leading underscores for method parameters is strange.

  • User profile image
    beadroux

    Thanks guys. The underscores were in the teachers template. The problem was to calculate the cost of a call giving the day, length and price. He has been teaching so fast I am missing stuff. Just trying anything to better understand this stuff.

  • User profile image
    AndyC

    A method will usually look something a bit like this:

    returntype DoSomething(argtype1 ThingComingIn1, argtype2 ThingComingIn2)
    
    {
       //declare something to hold our result
       returntype ThingGoingOut;
    
       //do whatever processing we need, in this case adding
       ThingGoingOut = ThingComingIn1 + ThingComingIn2
    
       //hand the result of our processing back to the caller
       return ThingGoingOut
    
    }
    

    If you try restructuring your methods to follow that kind of pattern, you'll be along the right lines. Don't have parameters if the method doesn't need them, like GetDay in your example, an empty argument list is perfectly acceptable.

    Applying that to your GetDay function, for example, we can see that the method should look a bit like this:

    string GetDay()
    {
         //declare a temporary variable to hold our result
         string result;
    
    
         // Do something here to get the day from the user
         // You need to fill this bit in
         result = ...
         //Pass that back to our caller
         return result
    }

    Keep going along those lines and you'll get there eventually.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.