CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2013
    Posts
    3

    What is wrong with this simple code

    using System;

    class Program
    {
    static void Main
    {
    string userInput;
    int userGrade;

    Console.WriteLine("========================================================");
    Console.WriteLine("Enter in your score to find out what grade you have got.");
    Console.WriteLine("========================================================");
    Console.WriteLine("");

    userInput = Console.ReadLine;
    userGrade = int.Parse(userInput);

    switch (userGrade)
    {
    case <35:
    Console.WriteLine("F");
    break;

    case >=35 && <=39:
    Console.WriteLine("E");
    break;

    case >=40 && <=39:
    Console.WriteLine("D");
    break;

    case >=50 && <=59:
    Console.WriteLine("C");
    break;

    case >=60 && <=69:
    Console.WriteLine("B");
    break;

    case >=70:
    Console.WriteLine("A");
    break;
    }
    }
    }

  2. #2
    Join Date
    Sep 2013
    Posts
    3

    Re: What is wrong with this simple code

    I get an error saying, get and set accessors expected

  3. #3
    Join Date
    Sep 2013
    Posts
    3

    Re: What is wrong with this simple code

    I have progressed but all I need to do now it to get the switch statement to work with something like case <35:.

    I can't only get it to work with case 1: ... etc..


    Any possible way in doing this.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: What is wrong with this simple code

    Use the default: case item and check for < 35 in there.

    Keep in mind that you can 'stack' several case statements on top of each other, if that helps.

    Code:
    switch(value)
    {
      case 3:
      case 6:
      case 8:
        DoWork();
        break;
      default:
        if(value < 35)
        {
          DoOtherWork();
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured