we have corn!!

This is a discussion on we have corn!! within the C Programming forums, part of the General Programming Boards category; lol i just need some help with this problem. my question is, which statements to consider. Im assuming the "if" ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Location
    vermont
    Posts
    9

    Arrow we have corn!!

    lol i just need some help with this problem. my question is, which statements to consider. Im assuming the "if" statement to start. Remember I'm a complete noob to this and any tips would be greatly appreciated!

    here it is:

    1. Hey, this is Vermont -- we've got corn!

    Write a program that accepts the number of ears of corn the customer is purchasing and outputs the total price. The corn is priced according to the following four statements:

    If the customer is purchasing less than a dozen ears, the price per ear is $0.50.
    If the customer is purchasing 12 to 23 ears, the price per ear is $0.45.
    If the customer is purchasing 24 to 35 ears, the price per ear is $0.40.
    If the customer is purchasing more than 35 ears, the price per ear is $0.35.

    You will need to use scanf to ask the user for the number of ears of corn being purchased, and then figure out the correct price to display. Ideally, you should only use 2 printfs, one to ask for the number of ears, and one which displays the total price

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I don't think "which statements to consider" is an approach that has ever really worked in programming. Figure out what you want to do. Once you know what you want to do, that will tell you what statements to use to make it happen.

    First step, then, is: write out, in English, the steps the program should take.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Location
    vermont
    Posts
    9
    tab,

    you have brought a very important point. Thank you

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by theor23 View Post
    lol i just need some help with this problem. my question is, which statements to consider. Im assuming the "if" statement to start. Remember I'm a complete noob to this and any tips would be greatly appreciated!
    Writing code is the *last* step in programming... The first step is understanding the problem that is to be solved... Then comes defining a solution... then you need to write code. Believe me, if you don't understand how to solve the problem, you will never write the software...

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    'if' statements seem reasonable. Mimic the same as the English description...
    Something like...
    Code:
    if (ears < 12)
        cost = 0.5;
    else if (ears < 24)
        cost = 0.45;
    else if (ears < 36)
        cost = 0.4;
    else cost = 0.35;

  6. #6
    Registered User
    Join Date
    Feb 2011
    Location
    vermont
    Posts
    9
    Quote Originally Posted by CommonTater View Post
    Writing code is the *last* step in programming... The first step is understanding the problem that is to be solved... Then comes defining a solution... then you need to write code. Believe me, if you don't understand how to solve the problem, you will never write the software...
    I'm really glad you brought this point up. I will follow this rule of thumb always, thanks again

  7. #7
    Registered User
    Join Date
    Feb 2011
    Location
    vermont
    Posts
    9
    thank you nonoob

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's a Trillion? and do we have an Echo Forum?
    By Adak in forum A Brief History of Cprogramming.com
    Replies: 58
    Last Post: 03-24-2009, 09:31 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21