C# Assignment help

Agh, okies I'm trying to loop my if statement, which loop should I use?

if (Tnumber > 25)
{
Console.Write("Invalid input!\n\nPlease enter a table number between 1 and 25: ");
Tnumber = Int32.Parse(Console.ReadLine());
}
Basically what the objective is, that if the user keeps entering a value higher than 25 it should continue to show that message until such time that a value below 25 is entered.. also whilst I'm asking... Can you also tell me how do I add another clause so that anything but the numbers between 1 and 25 also returns the same error message.

Thanks =)

Replies

  • shalini_goel14
    shalini_goel14
    Hi Black_Rose,

    I guess you can better use do...while loop

    something like below:
    ...
    do{
    if (Tnumber > 25)
    {
    Console.Write("Invalid input!\n\nPlease enter a table number between 1 and 25: ");
    Tnumber = Int32.Parse(Console.ReadLine());
    } 
    else
    {
    Console.Write("Invalid input!\n\nPlease enter a table number between 1 and 25: ");
    break;
    
    } 
    }while(Tnumber > 0)  // or condition that proves that user has input a number.
     
    
    Hope I understood your problem and have answered well. 😀
  • Black_Rose
    Black_Rose
    Shalini, that's absolutely perfect thank you. I attempted the do while loop, but messed it up somehow :S I've changed the following on your code:

    else
    {
    Console.Clear ();
    break;
    }
    Just so when I'm done it clears the screen and displays new information.

    =)
  • Black_Rose
    Black_Rose
    Okay this is another part I'm struggling to understand. I'm asking the user to code in p for pizza and d for drinks. If it's a p then a pizza menu will show up if d is typed in than a drinks menu. How do I assign the 'd' and 'p' to show their respective menus? I've done the following:

    Console.WriteLine("\n\n\t\t\tPlease enter which menu you would like to order from: \n\n\t\t\t\t1) Type 'p' for Pizza \n\n\t\t\t\t2) Type 'd' for Drinks\n");
    Console.ReadLine();
    =)
  • shalini_goel14
    shalini_goel14
    Hi Black_Rose,

    I am not sure whether you tried something like following:

    Console.WriteLine("\n\n\t\t\tPlease enter which menu you would like to order from: \n\n\t\t\t\t1) Type 'p' for Pizza \n\n\t\t\t\t2) Type 'd' for Drinks\n");
     
    // assigns whatever user enters to a variable menuSelectOption
    String menuSelectOption= Console.ReadLine(); 
    
    Hope I understood your problem correctly. 😀
  • Black_Rose
    Black_Rose
    Shalini, thanks alot for your help, don't worry I found out I need to use switch statements =) <3

You are reading an archived discussion.

Related Posts

Hi, Actually I have completed my engineering in electronics and communication, and i am already doing job also. But I have very much interest in mobile communications technology such as...
Can any one suggest me few topics regarding to mini project on Piping Engineering.
Hello folks first post on this site. Im currently at college doing a project for my HND (Higher National Diploma) and I have to make a solar paneled air conditioning...
Hi, I am in 8th sem & want to do higher studies.which one I must prefer-MTEC or MBA?
I received a very nice forward mail which I thought I should share with all. Lets see what and how much effects it leaves on everybody. If you like this...