Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   What's wrong with my code? (http://www.programmingforums.org/showthread.php?t=13802)

Sparrow Aug 19th, 2007 12:31 AM

What's wrong with my code?
 
Hi everyone,

I try to make a program that will ask the user for their ice cream flavor and the most they can have is three scoops.

It needs to throw an exception if they do not go with the five flavors and if they go beyond 3 scoops.

Also right at the begining of testing it will get a bug error immediatly with no build errors..and then crash..need help! Could someone tells me what's wrong with my code below?

Thanks!

:

  1. using System;
  2.  
  3. namespace IceCreamConeExceptionDemo.cs
  4. {
  5.  
  6.     class IceCreamCone
  7.     {
  8.  
  9.         [STAThread]
  10.         static void Main(string[] args)
  11.         {
  12.             string[] IceCreamFlavor = new string[5];
  13.             IceCreamFlavor[0] = "vanilla";
  14.             IceCreamFlavor[1] = "chocolate";
  15.             IceCreamFlavor[2] = "strawberry";
  16.             IceCreamFlavor[3] = "peach";
  17.             IceCreamFlavor[4] = "banana";
  18.             int scoops;
  19.             scoops = 3;
  20.             int result;
  21.             int max;
  22.             char response;
  23.             max = 3;
  24.             Console.Write("Pick a {0} ", IceCreamFlavor.Length);
  25.             response = GetChar();
  26.             try
  27.             {
  28.                 Console.Write("Pick another {0} ", IceCreamFlavor.Length);
  29.                 Console.Read();
  30.                 response = GetChar();
  31.             }
  32.             catch (FormatException e)
  33.             {
  34.                 throw (e);
  35.             }
  36.             Console.Write("How many {0} ", scoops);
  37.             response = GetChar();
  38.             if (response == scoops + max)
  39.                 Console.WriteLine("Thank you for your order");
  40.             else
  41.             {
  42.                 Console.Write("Re-enter amount of scoops");
  43.                 ++scoops;
  44.                 result = scoops / max;
  45.             }
  46.         }
  47.         public static Char GetChar()
  48.         {
  49.             string inputString;
  50.             inputString = Console.ReadLine();
  51.             char response;
  52.             response = Convert.ToChar(inputString);
  53.             return response;
  54.         }
  55.  
  56.         public static void GetFlavor()
  57.         {
  58.             string[] IceCreamFlavor = new string[5];
  59.             IceCreamFlavor[0] = "vanilla";
  60.             IceCreamFlavor[1] = "chocolate";
  61.             IceCreamFlavor[2] = "strawberry";
  62.             IceCreamFlavor[3] = "peach";
  63.             IceCreamFlavor[4] = "banana";
  64.  
  65.         }
  66.     }
  67. }


Booooze Aug 19th, 2007 12:43 AM

Put it in code tags and maybe you'll get a helpful response.

Infinite Recursion Aug 19th, 2007 12:50 AM

Agreed with Booooze... I didn't bother reading the code because its not in the [ CODE ] tags.

xavier Aug 19th, 2007 1:03 AM

Better yet, wrap it in [highlight=csharp][/*highlight] - without the * offcorse.

Sparrow Aug 19th, 2007 1:15 AM

Hi there,

What do you mean by code tags??? I know that I'm not as good as you are in programming...

Sparrow Aug 19th, 2007 1:16 AM

Hi there,

Everybody's speaking to write my code in code tags... what is it?
Thanks!

titaniumdecoy Aug 19th, 2007 1:40 AM

Code tags

Sparrow Aug 19th, 2007 2:19 AM

Hi There,

How do I do that? I just starded programming...
Tx!

Kelvoron Aug 19th, 2007 2:37 AM

lol hi sparow, i haven't read your problem yet but when they say code tags they mean on here when you post (in normal post not quick reply) you will see a little # symbol in the tool bar under the title filed click it and it will give you two tags that say code and /code with brakets around it. put your code in that for people to view.

:

System.Console.WriteLine("your code will apear like this.");
System.Console.ReadLine();

      /*see
        code
          tags*/
// are cool


Kelvoron Aug 19th, 2007 2:51 AM

...... this question is stright from a solve it problem in Visual C#.net by: Joyce Farell ...... im not even attempting to help


All times are GMT -5. The time now is 2:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC