Question line needs ) and } ?

Ahmet

New member
Joined
Dec 7, 2020
Messages
2
Programming Experience
Beginner
can somebody help me about something like this
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp1
{
    internal class Fabric
    {
        static void Main(string[] args)
        {
            Console.WriteLine("1\'den 7\'ye Kadar Bir Numara Yazınız");
            int gün = Convert.ToInt32(Console.ReadLine());
            do
            {
                switch (gün)
                {
                    case 1:
                        Console.WriteLine("Pazartesi");
                        break;
                    case 2:
                        Console.WriteLine("Salı");
                        break;
                    case 3:
                        Console.WriteLine("Çarşamba");
                        break;
                    case 4:
                        Console.WriteLine("Perşembe");
                        break;
                    case 5:
                        Console.WriteLine("Cuma");
                        break;
                    case 6:
                        Console.WriteLine("Cumartesi");
                        break;
                    case 7:
                        Console.WriteLine("Pazar");
                        break;
                }
            } while (gün > 0; gün < 8; );
        }
    }
}
i dont understand what am i supposed to do it says in while in the fortieth line needs ) and } im using vs 2019 .net c#
pls help
 
Last edited by a moderator:
Firstly, a few pointers on posting properly.
  1. Please format your code for readability.
  2. Formatting code properly also allows you to highlight one or more lines you want to draw attention to.
  3. Please provide a title that summarises the issue you're having. Everyone wants help, so asking for help is as much use as no title at all.
 
As for the issue, that while line needs to be a Boolean expression, like what you would use in an if statement. If you want to specify multiple conditions then you combine them with Boolean operators:
C#:
} while (gün > 0 && gün < 8);
Once you fix that though, you'll be notified of another issue. You're looping while a variable is within a particular range but that variable never changes inside the loop, so it will either execute once only or forever. I suspect that you actually want to read the input inside the loop rather than outside:
C#:
int gün;

do
{
    gün = Convert.ToInt32(Console.ReadLine());

    switch (gün)
    {
        case 1:
            Console.WriteLine("Pazartesi");
            break;
        case 2:
            Console.WriteLine("Salı");
            break;
        case 3:
            Console.WriteLine("Çarşamba");
            break;
        case 4:
            Console.WriteLine("Perşembe");
            break;
        case 5:
            Console.WriteLine("Cuma");
            break;
        case 6:
            Console.WriteLine("Cumartesi");
            break;
        case 7:
            Console.WriteLine("Pazar");
            break;
    }
} while (gün > 0 && gün < 8);
 
can i ask something ?
how can I return the entry to the beginning if it doesn't type in the range of numbers I want?
 
You've got a couple of choices:
Option 1: Put another loop around the initial input request which will keep on repeating until a number in the acceptable range is entered. In pseudocode it would look something like:
C#:
do
{
    do
    {
        Get number from user
    } while (number is not in valid range);

    Do something with a valid number
} while (number is in valid range);

Option 2: Just have an infinite loop and just do something with a number that is in the valid range (which is what your current switch seems to be doing anyway). In pseudocode it would look something like like:
C#:
while (true)
{
    Get number from user
    Do something with a valid number
}

Option 2 is viable because your current switch statement doesn't have a default case to deal with invalid numbers. So if an invalid number is entered, you won'd do anything anyway, and the loop will go back to the top and get the next input.
 
Last edited:
Back
Top Bottom