List Info

Thread: C-Sharp (C#) Group: Having trouble with a project for school




C-Sharp (C#) Group: Having trouble with a project for school
user name
2006-07-19 20:09:12
Having trouble with a project for school. It will buils but
it has
exceptions. The code is below. any help will be appreciated.

using System;

namespace IceCreamConeExceptionDemo.cs
{

	class IceCreamCone
	{

		[STAThread]
		static void Main(string[] args)
		{
			string[] IceCreamFlavor = new string[5];
			IceCreamFlavor [0] = "vanilla";
			IceCreamFlavor [1] = "chocolate";
			IceCreamFlavor [2] = "strawberry";
			IceCreamFlavor [3] = "peach";
			IceCreamFlavor [4] = "banana";
			int scoops;
			scoops = 3;
			int result;
			int max;
			char response;
			max = 3;

			Console.WriteLine("Pick a flavor, 0 = vanella, 1 =
chocolate, 2 =
strawberry");
			Console.WriteLine("3 = peach, 4 = banana");

			response = GetChar();
			try
			{
				Console.WriteLine("Pick another",
IceCreamFlavor.Length);
				Console.Read();
				response = GetChar();
			}

			catch (FormatException e)
			{
				throw(e);

			}
			Console.Write("How many scoops");
				++scoops;
			response = GetChar();
			if (response == scoops + max)
				Console.WriteLine("Thank you for your
order");
			else
			{
				Console.Write("Re-enter amount of scoops");
				++scoops;
				result = scoops / max;
			}
		}
		public static Char GetChar()
		{
			string inputString;
			inputString = Console.ReadLine();
			char response;
			response = Convert.ToChar(inputString);
			return response;
		}

		public static void GetFlavor()
		{
			string[] IceCreamFlavor = new string[5];
			IceCreamFlavor [0] = "vanilla";
			IceCreamFlavor [1] = "chocolate";
			IceCreamFlavor [2] = "strawberry";
			IceCreamFlavor [3] = "peach";
			IceCreamFlavor [4] = "banana";

		}
	}
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Having trouble with a project for school
user name
2006-07-19 21:17:17
Vinnie,
     Try this out. Please note the "//***
" structure for
anywhere I made changes, and why. I hope this helps.
---
using System;

namespace IceCreamConeExceptionDemo.cs
{
	class IceCreamCone
	{
		[STAThread]
		static void Main(string[] args)
		{
			string[] IceCreamFlavor = new string[5];
			IceCreamFlavor[0] = "vanilla";
			IceCreamFlavor[1] = "chocolate";
			IceCreamFlavor[2] = "strawberry";
			IceCreamFlavor[3] = "peach";
			IceCreamFlavor[4] = "banana";
			int scoops;
			scoops = 3;
			int result;
			int max;
			char response;
			max = 3;
			Console.WriteLine("Pick a flavor, 0 = vanella, 1 =
chocolate, 2 =
strawberry");
			Console.WriteLine("3 = peach, 4 = banana");

			response = GetChar();
			try
			{
				Console.WriteLine("Pick another",
IceCreamFlavor.Length);
				//*** I commented this, as it was doing nothing.
				//Console.Read();
				response = GetChar();
			}
			catch (FormatException e)
			{
				throw (e);
			}
			Console.WriteLine("How many scoops");
			++scoops;
			response = GetChar();
			if (response == scoops + max)
			{
				Console.WriteLine("Thank you for your
order");
				//*** I added the blank read line to allow
				//*** the application to stay open for review.
				//*** This will force you to press enter to exit.
				Console.ReadLine();
			}
			else
			{
				Console.Write("Re-enter amount of scoops");
				++scoops;
				result = scoops / max;
			}
		}
		public static Char GetChar()
		{
			string inputString;
			inputString = Console.ReadLine();
			char response;
			//*** I made sure that the response would
			//*** only be the first character.
			response = Convert.ToChar(inputString[0]);
			return response;
		}


		public static void GetFlavor()
		{
			string[] IceCreamFlavor = new string[5];
			IceCreamFlavor[0] = "vanilla";
			IceCreamFlavor[1] = "chocolate";
			IceCreamFlavor[2] = "strawberry";
			IceCreamFlavor[3] = "peach";
			IceCreamFlavor[4] = "banana";
		}
	}
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )