Pizza program help

Pizza program for aq sales assistant

Page 1 of 1

7 Replies - 2695 Views - Last Post: 03 January 2011 - 10:16 AM Rate Topic: -----

#1 smithm21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-January 11

Pizza program help

Posted 03 January 2011 - 08:17 AM

Hi there!

Looking for some help with a simple c# console application program (brief attached). I am working on an assignement and am really struggling to put the pieces together.

Here's what I have so far (having trouble with the array aspect to get the baseprice and also with strings converting into numbers):

static void Main(string[] args)
{
const double cost1 = 5;
const double cost2 = 3;
const double cost3 = 1.50;

const double pie = 3.14159;
double metrecost = 30;

const int SIZEMIN = 120;
const int SIZEMAX = 1000;

double radius;
string pizzasizeString;
double pizzasize;
double qualitycase;
double baseprice;
double pizzaprice;

string[] selectcase = { "Supreme", "Best Brand", "Regular" };
for (int i = 0; i < selectcase.Length; i++)
Console.WriteLine("{0} {1}", i + 1, selectcase[i]);
Console.Write("Please enter which type of pizza the customer would like to buy: ");
double.Parse(qualitycase) = Console.ReadLine(); // Read input

if (qualitycase == 1)
{
baseprice = cost1;
}
else if (qualitycase == 2)
{
baseprice = cost2;
}
else if (qualitycase == 3)
{
baseprice = cost3;
}
else
{
Console.WriteLine("That is an invalid choice please select option 1, 2 or 3");

}

{ //Calculate area and cost of pizza

do
{
Console.Write("Please enter the size of the pizza that the customer would like to buy between " + SIZEMIN + " and " + SIZEMAX + " :");
pizzasizeString = Console.ReadLine();
pizzasize = double.Parse(pizzasizeString);
} while (pizzasize < SIZEMIN || pizzasize > SIZEMAX);

radius = (pizzasize / 2) / 1000; //Size is diameter in mm so divide by 2
//Divide by 100 to get metreage

pizzaprice = ((pie * (radius * radius)) * metrecost) + baseprice;
}

}
}

} 



Any help would be greatly appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: Pizza program help

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4422
  • View blog
  • Posts: 7,690
  • Joined: 08-June 10

Re: Pizza program help

Posted 03 January 2011 - 08:27 AM

You didn't really ask a question...or even tell us what the requirements of the program are (which wouldn't help anyway, since we won't do your work for you).

So, what's the problem? Please be specific about exactly what you're having trouble with, and what lines it's happening on, and any error messages you get.
Was This Post Helpful? 0
  • +
  • -

#3 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: Pizza program help

Posted 03 January 2011 - 08:27 AM

Hello there,

Very specifically, what parts of your program are not working as you want, and what are they doing vs what they should be doing?

This line:

double.Parse(qualitycase) = Console.ReadLine(); // Read input 


is meaningless and will throw compiler errors all over the place...

Your parsing the value of qualitycase to a double, then assigning the string value from the console to that. Basically, it is equvalent to this:

0.6 = "Hello";



I'm sure you can see that that doesn't make sense.

I think what you should have done is something like this:

qualitycase = double.Parse(Console.ReadLine());


That is then parsing the value the user enters and storing it in the qualitycase variable.

Plus, you have missed the curly braces off the body of your for loop...

This post has been edited by CodingSup3rnatur@l-360: 03 January 2011 - 08:45 AM

Was This Post Helpful? 2
  • +
  • -

#4 smithm21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-January 11

Re: Pizza program help

Posted 03 January 2011 - 08:40 AM

Hey yer sorry i tried attaching the document but it obviously didnt work. The part that I was looking for help on was the array select case. I am not asking for you to do my homework for me, just after a bit of advise on where i may be going wrong as my tutors replies seem to come about a week too late. A quick brief is:

Project Specification:
A Pizza making company produces bespoke Pizzas. Each one is a different size and quality, but
they are all round in shape.
The pizzas are priced as follows:
First, a fixed charge is made according to the quality. There are three levels of quality:
Supreme The fixed charge is 5.00
Best brand The fixed charge is 3.00
Regular The fixed charge is 1.50.
Then a charge is made according to the area of the pizza, at a rate of 30 per square metre.
You should write a program to allow a sales assistant to calculate the price of a pizza, and then
store the details of each sale in a text file, to allow later analysis of sales data.
The program should ask the operator for the quality of the pizza. It is recommended that you use
1 for Supreme, 2 for Best brand and 3 for Regular. To avoid the risk of operator error,
write the selection name back to the operator, and provide a means for the operator to cancel the
selection and re-enter the correct quality. You should trap operator errors (eg entering an invalid
number or text) and write a helpful message and request re-entry of the invalid data.
Next, ask for the diameter of the pizza in millimetres. Check for valid input as above. See the
note at the end that gives the limits that you should check for on the diameter.
Finally, print out the cost of the pizza in pounds and rounded to the nearest penny. After this is
done you should allow the sales assistant to confirm that the details and price are correct, or to
correct details (for example if a mistake was made); thus the operator can cancel the order and
start again.
Was This Post Helpful? 0
  • +
  • -

#5 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Pizza program help

Posted 03 January 2011 - 08:52 AM

You're missing braces on your for loop.

Break down what you're supposed to do and tackle one subproblem at a time. Also format your code (read my signature) before posting.
Was This Post Helpful? 1
  • +
  • -

#6 smithm21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-January 11

Re: Pizza program help

Posted 03 January 2011 - 08:59 AM

Hi Sergio,
Thanks - I will format code in future!
Mike

The main problem i am having now is 'baseprice' is an unassigned variable. My array is clearly broken and I am wondering if I have made it a bit too complicated for what is needed. My intention is so that when a user selects for example option 1, that will assign the variable baseprice with the price for option 1 which is Cost 1, so baseprice should then = 5
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,643
  • Joined: 02-June 10

Re: Pizza program help

Posted 03 January 2011 - 10:16 AM

View Postsmithm21, on 03 January 2011 - 07:59 AM, said:

The main problem i am having now is 'baseprice' is an unassigned variable.

Then assign something to the variable.

Quote

double radius;
string pizzasizeString; // unassigned variable
double pizzasize; // unassigned variable
double qualitycase; // unassigned variable
double baseprice; // unassigned variable
double pizzaprice; // unassigned variable

// Look at that, a bunch of unassigned variables that later try to get used.

if (qualitycase == 1)
{
baseprice = cost1;
}
else if (qualitycase == 2)
{
baseprice = cost2;
}
else if (qualitycase == 3)
{
baseprice = cost3;
}
else
{
Console.WriteLine("That is an invalid choice please select option 1, 2 or 3");

}



Dude. Get some sleep so you can start to think.

The error TELLS YOU the problem. Your variables have nothing assigned to them before you try to use them. So assign something to them when you make them.
Was This Post Helpful? 0
  • +
  • -

#8 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: Pizza program help

Posted 03 January 2011 - 10:16 AM

I think you could simply use an enumeration instead of an array. It could look like this:


//could declare this at namespace level (after namespace declaration but before class declaration)
public enum PizzaType
    {
        Supreme = 1,
        BestBrand = 2,
        Regular = 3
    }




Notice how each of the names are mapped to 1,2,3 respectively to allow easy processing when the user enters 1,2 or 3 to select the pizza type. Once the pizza type is selected, you store it in a variable of type PizzaType.

private static PizzaType pizzaType; //this can hold selected pizza type


You can then use your if statements (a switch statement would be more appropriate in this case) to select the relevant price based on the value of the pizzType variable.

Also, the Math class defines the PI constant. I would use that, instead of hardcoding your own value, as so:

Math.PI;

This post has been edited by CodingSup3rnatur@l-360: 03 January 2011 - 10:39 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1