Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 18th, 2007, 11:31 PM   #1
Sparrow
Newbie
 
Join Date: Aug 2007
Posts: 2
Rep Power: 0 Sparrow is on a distinguished road
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!

csharp Syntax (Toggle Plain Text)
  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. }

Last edited by big_k105; Aug 19th, 2007 at 7:05 PM. Reason: Added highlight tag
Sparrow is offline   Reply With Quote
Old Aug 18th, 2007, 11:43 PM   #2
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
Put it in code tags and maybe you'll get a helpful response.
Booooze is offline   Reply With Quote
Old Aug 18th, 2007, 11:50 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Agreed with Booooze... I didn't bother reading the code because its not in the [ CODE ] tags.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 19th, 2007, 12:03 AM   #4
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 379
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
Better yet, wrap it in [highlight=csharp][/*highlight] - without the * offcorse.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Aug 19th, 2007, 12:15 AM   #5
Sparrow
Newbie
 
Join Date: Aug 2007
Posts: 2
Rep Power: 0 Sparrow is on a distinguished road
Hi there,

What do you mean by code tags??? I know that I'm not as good as you are in programming...
Sparrow is offline   Reply With Quote
Old Aug 19th, 2007, 12:16 AM   #6
Sparrow
Newbie
 
Join Date: Aug 2007
Posts: 2
Rep Power: 0 Sparrow is on a distinguished road
Hi there,

Everybody's speaking to write my code in code tags... what is it?
Thanks!
Sparrow is offline   Reply With Quote
Old Aug 19th, 2007, 12:40 AM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 841
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Code tags
titaniumdecoy is offline   Reply With Quote
Old Aug 19th, 2007, 1:19 AM   #8
Sparrow
Newbie
 
Join Date: Aug 2007
Posts: 2
Rep Power: 0 Sparrow is on a distinguished road
Hi There,

How do I do that? I just starded programming...
Tx!
Sparrow is offline   Reply With Quote
Old Aug 19th, 2007, 1:37 AM   #9
Kelvoron
Programmer
 
Kelvoron's Avatar
 
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0 Kelvoron is on a distinguished road
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
__________________
Good better best, never let it rest, untill your good is better and your better is the best.
Kelvoron is offline   Reply With Quote
Old Aug 19th, 2007, 1:51 AM   #10
Kelvoron
Programmer
 
Kelvoron's Avatar
 
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0 Kelvoron is on a distinguished road
...... this question is stright from a solve it problem in Visual C#.net by: Joyce Farell ...... im not even attempting to help
__________________
Good better best, never let it rest, untill your good is better and your better is the best.
Kelvoron is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is wrong with this code? c0ldshadow Visual Basic .NET 5 Dec 5th, 2005 5:37 PM
How to post a question nnxion C++ 10 Jun 3rd, 2005 11:53 AM
How to post a question nnxion C++ 0 Jun 3rd, 2005 8:55 AM
How to post a question nnxion C 0 Jun 3rd, 2005 8:55 AM
Any ideas what i've done wrong? (Newb C Programmer) Code included Ramlag C++ 10 Mar 22nd, 2005 1:57 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:36 AM.

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