I dont know where to start or how to start

You should start with the math. Figure out what you want the program to calculate and how to calculate it. Once you get that straight, writing the perl script will be very easy.

You want to find the profit. And you have 10 pizzas. Let's find the profit for one pizza first and then we multiply it by 10. Okay?

The profit equals income - expense. Income is the price you get for the pizza, and expense is what you pay for the ingredients and cooking and labor, etc.

In this case, figuring out the expense is easy, because we are told that the pizza price is 250. So, 250 includes all the expenses. The income is 300, because that's what you're selling it for. And the difference is 50. That's your profit. That's the question.

But then what if you sell the pizza 10% cheaper? Now, instead of selling it for 300, you sell it for 270, because that's 10% less. Now, if you pay 250 for the pizza and sell it for 270, then you still have a profit of 20 on each pizza.

So, the math is pretty simple... Yes, writing the perl code is also simple, but you have to figure it out yourself.

Every perl program starts with the same three lines of code. And this is just to get you started:

#!/usr/bin/perl -w

use strict;
use warnings;

my $A = 250; # Pizza price
my $B = 300; # Selling price
my $C = $B - $A; # Difference
print "A = $A \n B = $B \n C = $C \n";

In programming languages, when you write A = 4, that's not a math equation. It's an instruction for the processor to store the value "4" in a memory location which we label as "A" If you want to do a multiplication, then you would do something like:

A = 4 * 12;

But in perl, every label or variable I should say is preceded by a $ sign. And you should declare the variable before you use it. That means the first time you assign a value to it, you should put the word "my" in front of it:

my $A = 4;

If you want to do multiplication in perl, you would do:

my $A = 4 * 12;
$A = $A * 2;

When you multiply a value by something else, you can write it as :

my $A = 2;
$A *= 5;
print $A; # Output: 10

Hope that wasn't too confusing.


In reply to Re: Please Help! This is a class assignment given to me. by harangzsolt33
in thread Please Help! This is a class assignment given to me. by vidyadithya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.