I'm new to coding need a little help please

I got the first part done and not sure how to do the second

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 3483 Views - Last Post: 26 September 2009 - 10:33 AM Rate Topic: -----

#1 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

I'm new to coding need a little help please

Posted 25 September 2009 - 12:32 PM

5_1) Dolly owns an image consulting shop. Her clients can select from the following services at the specified regular prices: Makeover $120, Hair Styling $65, Manicure $25, and Permanent Makeup $190. She has distributed discount coupons that advertise discounts of 15 percent and 25 percent off the regular price. Create an application that will allow the receptionist to select a discount rate of 15 percent, 25 percent, or none, and then select a service. Display the price for the individual service and the total due.

using System;
using System.Collections.Generic;
using System.Text;

namespace _._
{
	class Program
	{
		static void Main(string[] args)
		{


			string choice;
			//input choices
			Console.Write("Please choose from a discount in percentages(type in number or word)");
			Console.WriteLine();
			Console.Write("twenty five , fifteen , zero");
			Console.WriteLine();
			choice = Console.ReadLine();


			string next = choice;
		//input choices that jump to the next decision
			switch (next)
			{
				case "twenty five":
				case "25": Console.WriteLine("next");
					break;
				case "fifteen":
				case "15": Console.WriteLine("next");
					break;
				case "zero":
				case "0": Console.WriteLine("next");
					break;
					
			}
			{	 // choose service after picking how much to take away
				Console.Write("please choose the service you would like");
				Console.WriteLine();
				Console.Write("make over(120$), hair styling(65$), manicure(25$), permanent makeup(190$)");
				Console.WriteLine();
				Console.Write("type name or price");
				Console.WriteLine();
				choice = Console.ReadLine();
			}
			switch (choice)
			{
					//after picking both percentage and product the answer will come up
					// different words in case customer types it different

				case "make over":
				case "make":
				case "120":
					if ((next) == "25")
					Console.WriteLine("final price{0:c}", 120 - .25 * 120);
					if ((next) == "twenty five")
					Console.WriteLine("final price{0:c}", 120 - .25 * 120);
					else if ((next) == "15")
					Console.WriteLine("final price{0:c}", 120 - .15 * 120);
					else if ((next) == "fifteen")
					Console.WriteLine("final price{0:c}", 120 - .15 * 120);
					if ((next) == "0")
					Console.WriteLine("final price{0:c}", 120 - .0 * 120);
					if ((next) == "zero")
					Console.WriteLine("final price{0:c}", 120 - .0 * 120);
					break;
					// all options for each percentage is given, 25, 15 and 0
				case "hair styling":
				case "hair":
				case "styling":
				case "65":
					if ((next) == "25")
						Console.WriteLine("final price{0:c}", 65 - .25 * 120);
					if ((next) == "twenty five")
						Console.WriteLine("final price{0:c}", 65 - .25 * 120);
					else if ((next) == "15")
						Console.WriteLine("final price{0:c}", 65 - .15 * 120);
					else if ((next) == "fifteen")
						Console.WriteLine("final price{0:c}", 65 - .15 * 120);
					if ((next) == "0")
						Console.WriteLine("final price{0:c}", 65 - .0 * 120);
					if ((next) == "zero")
						Console.WriteLine("final price{0:c}", 65 - .0 * 120);
					
					break;
				case "manicure":
				case "mani":
				case "25":
					if ((next) == "25")
						Console.WriteLine("final price{0:c}", 25 - .25 * 120);
					if ((next) == "twenty five")
						Console.WriteLine("final price{0:c}", 25 - .25 * 120);
					else if ((next) == "15")
						Console.WriteLine("final price{0:c}", 25 - .15 * 120);
					else if ((next) == "fifteen")
						Console.WriteLine("final price{0:c}", 25 - .15 * 120);
					if ((next) == "0")
						Console.WriteLine("final price{0:c}", 25 - .0 * 120);
					if ((next) == "zero")
						Console.WriteLine("final price{0:c}", 25 - .0 * 120);
					break;
				case "permanent makeup":
				case "permanent":
				case "makeup":
				case "190$":
					if ((next) == "25")
						Console.WriteLine("final price{0:c}", 190 - .25 * 120);
					if ((next) == "twenty five")
						Console.WriteLine("final price{0:c}", 190 - .25 * 120);
					else if ((next) == "15")
						Console.WriteLine("final price{0:c}", 190 - .15 * 120);
					else if ((next) == "fifteen")
						Console.WriteLine("final price{0:c}", 190 - .15 * 120);
					if ((next) == "0")
						Console.WriteLine("final price{0:c}", 190 - .0 * 120);
					if ((next) == "zero")
						Console.WriteLine("{0:c}", 190 - .0 * 120);
					
					break;
			}

			
			
		 

			Console.ReadLine();

		}
	}
}



I think im missing something in the final output but im sure I can fix that no problem

the part im having trouble with is this
5_2) Modify the prior exercise to allow for multiple services per client and additional patrons. At the end display in a summary the number of clients and the total dollar value for all services rendered to all customers.

how do I go about starting that?

Is This A Good Question/Topic? 0
  • +

Replies To: I'm new to coding need a little help please

#2 MentalFloss  Icon User is offline

  • .
  • member icon

Reputation: 577
  • View blog
  • Posts: 1,500
  • Joined: 02-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 12:45 PM

It depends. Have you learned what a "class" is? Or are you not that far in your study?

If you have, what you have should be changed considerably.

If you haven't, this is about to get pretty convoluted.
Was This Post Helpful? 1
  • +
  • -

#3 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 12:56 PM

View PostMentalFloss, on 25 Sep, 2009 - 11:45 AM, said:

It depends. Have you learned what a "class" is? Or are you not that far in your study?

If you have, what you have should be changed considerably.

If you haven't, this is about to get pretty convoluted.


I dont think so, it doesnt sound familiar
Was This Post Helpful? 0
  • +
  • -

#4 MentalFloss  Icon User is offline

  • .
  • member icon

Reputation: 577
  • View blog
  • Posts: 1,500
  • Joined: 02-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 01:00 PM

Well, what you have is contained in a class called Program.
C# programs are logically structured into classes to complete the work required.

As I see it, you need a couple other classes besides Program for what you have.

However, since you have not learned about classes yet, going this route will probably prompt questions from your teacher.

I personally think that your requirements demand delving into classes to make this easier to work with, but it all depends on whether or not you are comfortable with introducing the possibilities of a (probably) lengthy conversation with your instructor.
Was This Post Helpful? 0
  • +
  • -

#5 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 01:03 PM

ok I know what you are talking about but he hasnt taught us to do our problems like that yet

is there any way you can help me with what iv already got?
Was This Post Helpful? 0
  • +
  • -

#6 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 01:06 PM

First of all, you have to clean that mess you have written. For example, this switch statement does absolutely nothing:

			switch (next)
			{
				case "twenty five":
				case "25": Console.WriteLine("next");
					break;
				case "fifteen":
				case "15": Console.WriteLine("next");
					break;
				case "zero":
				case "0": Console.WriteLine("next");
					break;					
			}



That 10 lines of code equals this:
Console.WriteLine("next");



As it is just a homework, you should give user that much choices to how they write the input, just use numbers like this:
			Console.Write("Please choose a discount:");
			Console.WriteLine();
			Console.Write("0. 0%");
			Console.Write("1. 15%");
			Console.Write("2. 25%");
			Console.WriteLine();



And then, read the answer into a variable, check in which statement what it is and create a discout variable which is used in multiplying at the end:
			string choice = Console.ReadLine();
			int discountChoice next = int.Parse(choice);

			double discount = 0;

			switch (discountChoice)
			{
				case 0: 
					discount = 0;
					break;
				case 1: 
					discount = 0.15;
					break;
				case 0: 
					discount = 0.25;
					break;					
			}



Next, you do the same for the second switch:

				 // choose service after picking how much to take away
			Console.Write("please choose the service you would like");
			Console.WriteLine();
			Console.Write("1. Make over");
			Console.Write("2. Hair styling");
			Console.Write("3. Manicure");
			Console.Write("4. Permanent makeup");
			Console.WriteLine();
			choice = Console.ReadLine();
			
			int serviceChoice = int.Parse(choice);

			double serviceCost = 0;

			switch (choice)
			{
				case 1: // make over
					serviceCost = 120;
					break;
				case 2: // hair styling
					serviceCost = 65;
					break;
				case 3: // manicure
					serviceCost = 25;
					break;
				case 4: // permanent
					serviceCost = 190;
					break;
			}



And at the end, calculate the price:

double price = serviceCost - discount * serviceCost;
Console.WriteLine("final price{0:c}", price);



Also, after looking at the code you have, you also have a bug in the price: you multiply each price with $120 even though the user hasn't chosen make over.

Doesn't the above code look a little bit more maintainable?

After that's done, we can discuss the actual problem. For that, you'll need a while loop which asks user questions until he/she stops the execution.

As MentalFloss mentioned, the classes would help a lot here.

The loop goes like this:
1. Ask if the customer is new or old one
2a. If new, add one to calculator which holds information about clients
2b. Goto 3.
3. Ask for discount
4. Ask for Service
5. Calculate total price
6. Add the price into a list to the customer's index (List[customerCount] += totalPrice;)
7. Goto 1.
8. when user exits the loop, run a for loop which prints out the customer index and the price associated with that customer in the list.
Was This Post Helpful? 1
  • +
  • -

#7 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 01:14 PM

Thank you soo much, its just im a bit a lost in this class and thought id write plenty so the customer would have choices, but yours makes a lot more sense, I am cleaning mine up now

again thanks a lot
Was This Post Helpful? 0
  • +
  • -

#8 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 01:40 PM

im getting an error here

	 // choose service after picking how much to take away
			Console.Write("please choose the service you would like");
			Console.WriteLine();
			Console.Write("1. Make over");
			Console.Write("2. Hair styling");
			Console.Write("3. Manicure");
			Console.Write("4. Permanent makeup");
			Console.WriteLine();
			choice = Console.ReadLine();
		   int serviceChoice = int.Parse(choice);
			double serviceCost = 0;

			switch (choice)
			{
				case 1: // Make Over
					serviceCost = 120;
					break;
				case 2: // Hair Styling
					serviceCost = 65;
					break;
				case 3: // Manicure
					serviceCost = 25;
					break;
				case 4: // Permanent
					serviceCost = 190;
					break;
			
			}


it is saying cannot convert int to string
Was This Post Helpful? 0
  • +
  • -

#9 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 02:06 PM

nvm fixed it

thanks again! im def. gonna be a regular on this forum
Was This Post Helpful? 0
  • +
  • -

#10 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 05:24 PM

ok so I finished and came up with basically what you gave me THANK YOU

using System;
using System.Collections.Generic;
using System.Text;

namespace _._
{
	class Program
	{
		static void Main(string[] args)
		{

			string choice;
			//int servicechoice; 
			//input choices
			Console.Write("Please pick a discount");
			Console.WriteLine();
			Console.Write("0. 0%");
			Console.WriteLine();
			Console.Write("1. 15%");
			Console.WriteLine();
			Console.Write("2. 25%");
			Console.WriteLine();
			choice = Console.ReadLine();
			int discountchoice = int.Parse(choice);



			double discount = 0;


			switch (discountchoice)
			{
				case 0:
					discount = 0;
					break;
				case 1:
					discount = 0.15;
					break;
				case 2:
					discount = 0.25;
					break;
			}


			// choose service after picking how much to take away
			Console.Write("please choose the service you would like");
			Console.WriteLine();
			Console.Write("1. Make over");
			Console.WriteLine();
			Console.Write("2. Hair styling");
			Console.WriteLine();
			Console.Write("3. Manicure");
			Console.WriteLine();
			Console.Write("4. Permanent makeup");
			Console.WriteLine();
			choice = Console.ReadLine();
			//int serviceChoice = int.Parse(choice);
			double serviceCost = 0;

			switch (choice)
			{

				case "1": // Make Over
					serviceCost = 120;
					break;
				case "2": // Hair Styling
					serviceCost = 65;
					break;
				case "3": // Manicure
					serviceCost = 25;
					break;
				case "4": // Permanent
					serviceCost = 190;
					break;

			}

			double price = serviceCost - discount * serviceCost;
			Console.WriteLine("final price{0:c}", price);






			Console.ReadLine();
		}
	}
}



but im still not sure how to loop correctly, do I write all new code or stack it and how do I let it put down services multiple times
Was This Post Helpful? 0
  • +
  • -

#11 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 06:04 PM

ok new question I have to create a checking account

this is what I have so far

using System;

class DoLoop
{
	public static void Main()
	{
		string myChoice;

		do
		{
			// Print A Menu
			Console.WriteLine("My checking account\n");

			Console.WriteLine("D - Deposit");
			Console.WriteLine("W - Withdrawal");
			Console.WriteLine("C - Check");
			Console.WriteLine("S - Service fees");
			Console.WriteLine("Q - Quit\n");

			Console.WriteLine("Choice (D,W,C,S,or Q): ");

			// Retrieve the user's choice
			myChoice = Console.ReadLine();

			// Make a decision based on the user's choice
			string amountdeposit,amountwithdraw;
			switch (myChoice)
			{
					// allow user to deposit 
				case "D":
				case "d":
					Console.WriteLine("You wish to deposit?.");
					Console.WriteLine("How Much?(only in increments of 10)");
					amountdeposit = Console.ReadLine();
					int moneydeposit = int.Parse(amountdeposit);
					Console.WriteLine("{0:c} has been deposited", amountdeposit);
					Console.WriteLine("you have {0} in your account", amountdeposit);
					break;
				case "W":
				case "w":
					Console.WriteLine("You wish to make a withdrawal?.");
					Console.WriteLine("How Much?");
					amountwithdraw = Console.ReadLine();
					int moneywithdraw = int.Parse(amountwithdraw);
					Console.WriteLine("{0:c} has been withdrawn", amountwithdraw);
					Console.WriteLine("you have {0} in your account", amountdeposit - amountwithdraw);
					break;
				case "C":
				case "c":
					Console.WriteLine("You wish to check your balance.");
					break;
				case "S":
				case "s":
					Console.WriteLine("You wish to view services charges?");
					break;
				case "Q":
				case "q":
					Console.WriteLine("Bye.");
					break;
				default:
					Console.WriteLine("{0} is not a valid choice", myChoice);
					break;
			}

			// Pause to allow the user to see the results
			Console.Write("press Enter key to continue...");
			Console.ReadLine();
			Console.WriteLine();
		} while (myChoice != "Q" || myChoice != "q"); // Keep going until the user wants to quit
	}
}


how do I make it so each transaction is added or subtracted to a balance?
Was This Post Helpful? 0
  • +
  • -

#12 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 06:38 PM

also we have learned the class system apparently I missed part of a lecture or something
Was This Post Helpful? 0
  • +
  • -

#13 MentalFloss  Icon User is offline

  • .
  • member icon

Reputation: 577
  • View blog
  • Posts: 1,500
  • Joined: 02-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 06:54 PM

Ok. You may not have been taught what a class is. That's fine... some teachers wait a while to actually teach that (from what I can tell).
BUT, have you not learned about methods yet too?

You split the conceptually different parts of code into their own block called methods. Then you call the method - it does its work - you get the result out (short answer).

Anyway, let's work on putting this stuff into methods....

using System;

namespace MethodDemo
{
	public class DoLoop
	{
		// Since we can't use more than this single class, here are some stateful properties of balance etc.

		private static double balance;
		private static double withdraw;
		private static double deposit;

		private static void PrintMenu()
		{
			Console.WriteLine("My checking account\n");

			Console.WriteLine("D - Deposit");
			Console.WriteLine("W - Withdrawal");
			Console.WriteLine("C - Check");
			Console.WriteLine("S - Service fees");
			Console.WriteLine("Q - Quit\n");

			Console.WriteLine("Choice (D,W,C,S,or Q): ");
		}

		private static string GetUserInput()
		{
			return Console.ReadLine();
		}

		private static void ProcessSelection(string selection)
		{
			// Remove the need for all of those case-dependent choices
			// Uppercase in the switch is more prominent even if it's slower to convert to uppercase so I used ToUpper().
			selection = selection.ToUpper();

			switch (selection)
			{
				case "D":
					ProcessDeposit();
					break;
				case "W":
					ProcessWithdrawl();
					break;
				case "C":
					ProcessCheckBalance();
					break;
				case "S":
					ProcessViewServiceCharges();
					break;
				case "Q":
					QuitApplication();
					break;
				default:
					Console.WriteLine("{0} is not a valid choice", selection);
					break;
			}
		}

		// Method to handle deposits
		private static void ProcessDeposit()
		{
			string userInput = string.Empty;

			Console.WriteLine("You wish to deposit?.");
			Console.WriteLine("How Much?(only in increments of 10)");
			userInput = Console.ReadLine();
			deposit = Double.Parse(userInput);
			Console.WriteLine("{0:c} has been deposited", deposit);

			balance += deposit;

			Console.WriteLine("you have {0:C2} in your account", balance);
		}

		// Method to handle withdraws
		private static void ProcessWithdrawl()
		{
			string userInput = string.Empty;

			Console.WriteLine("You wish to make a withdrawal?.");
			Console.WriteLine("How Much?");
			userInput = Console.ReadLine();
			withdraw = Double.Parse(userInput);
			Console.WriteLine("{0:c} has been withdrawn", withdraw);

			balance -= withdraw;

			Console.WriteLine("you have {0} in your account", balance);
		}

		// Method to handle checking balance.
		private static void ProcessCheckBalance()
		{
			// Nothing terribly exciting here...
			Console.WriteLine("You wish to check your balance.");
		}

		// Method to handle service charges.
		private static void ProcessViewServiceCharges()
		{
			Console.WriteLine("You wish to view services charges?");
		}

		// This one could use some work. It doesn't actually quit the app right now, but I am moving your switch code to methods of their own...
		// So, probably want to revisit this.
		private static void QuitApplication()
		{
			Console.WriteLine("Bye.");
		}

		public static void Main()
		{
			string myChoice;

			do
			{
				// Code becomes:
				PrintMenu();
				myChoice = GetUserInput();
				ProcessSelection(myChoice);


				Console.Write("press Enter key to continue...");
				Console.ReadLine();
				Console.WriteLine();
			} while (myChoice != "Q" || myChoice != "q"); // Keep going until the user wants to quit



				// Print A Menu (Code has been moved to "PrintMenu()")
				//Console.WriteLine("My checking account\n");

				//Console.WriteLine("D - Deposit");
				//Console.WriteLine("W - Withdrawal");
				//Console.WriteLine("C - Check");
				//Console.WriteLine("S - Service fees");
				//Console.WriteLine("Q - Quit\n");

				//Console.WriteLine("Choice (D,W,C,S,or Q): ");


				// Not really much purpose of creating this method. It doesn't do much, but overdoing the concept will teach it easier
				// Code moved to method "GetUserInput()"
				// Retrieve the user's choice
				//myChoice = Console.ReadLine();



				// Moving all this code to "ProcessSelection()
				// Make a decision based on the user's choice
				//string amountdeposit, amountwithdraw;
				//switch (myChoice)
				//{
				//	// allow user to deposit
				//	case "D":
				//	case "d":
				//		Console.WriteLine("You wish to deposit?.");
				//		Console.WriteLine("How Much?(only in increments of 10)");
				//		amountdeposit = Console.ReadLine();
				//		int moneydeposit = int.Parse(amountdeposit);
				//		Console.WriteLine("{0:c} has been deposited", amountdeposit);
				//		Console.WriteLine("you have {0} in your account", amountdeposit);
				//		break;
				//	case "W":
				//	case "w":
				//		Console.WriteLine("You wish to make a withdrawal?.");
				//		Console.WriteLine("How Much?");
				//		amountwithdraw = Console.ReadLine();
				//		int moneywithdraw = int.Parse(amountwithdraw);
				//		Console.WriteLine("{0:c} has been withdrawn", amountwithdraw);
				//		Console.WriteLine("you have {0} in your account", amountdeposit - amountwithdraw);
				//		break;
				//	case "C":
				//	case "c":
				//		Console.WriteLine("You wish to check your balance.");
				//		break;
				//	case "S":
				//	case "s":
				//		Console.WriteLine("You wish to view services charges?");
				//		break;
				//	case "Q":
				//	case "q":
				//		Console.WriteLine("Bye.");
				//		break;
				//	default:
				//		Console.WriteLine("{0} is not a valid choice", myChoice);
				//		break;
				//}



				// This part's just commented out so I can do it higher up.. it will read better.
				// Pause to allow the user to see the results
			//	Console.Write("press Enter key to continue...");
			//	Console.ReadLine();
			//	Console.WriteLine();
			//} while (myChoice != "Q" || myChoice != "q"); // Keep going until the user wants to quit
		}
	}
}



So, I kept all of your original code in there... I commented it, but this should function just like what you have.

Take a little time to look over that. See how it flows? Does this make sense to you? There is, of course, more work we can do to this.

And, I haven't answered your current question.... but just take a little time to understand this concept.
Was This Post Helpful? 1
  • +
  • -

#14 jmartin51  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 25-September 09

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 07:09 PM

Thank you so much, the balance code is what got me, the check command doesnt work tho

if I change the code to just
console.writeline("{0}", balance);


would that just automatically take my balance?
Was This Post Helpful? 0
  • +
  • -

#15 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: I'm new to coding need a little help please

Posted 25 September 2009 - 07:33 PM

View Postjmartin51, on 25 Sep, 2009 - 08:09 PM, said:

Thank you so much, the balance code is what got me, the check command doesnt work tho

if I change the code to just
console.writeline("{0}", balance);


would that just automatically take my balance?


That would display your balance. You might want to format it though.

Console.WriteLine("Your balance is {0:C}", balance);

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2