I"m new to C++ programing and need help

I'm taking an introduction course to programming with C++ and the teacher gave us a HW assignment and I'm stuck with one of the questions I did the IPO chart but need to code the program can some one please explain it to me or help me in any way.

Question:
Builders Inc. needs a program that allows the company's salesclerk to enter both the diameter of a circle (in feet) and the price of railing material per foot. The diameter and the price may contain decimal places. The program should display both the circumference of the circle and the total price of the railing material. Use 3.141593 as the value of pi.

I have to create a code for this program and not sure how to write it can some one help me out.

Comments

  • : I'm taking an introduction course to programming with C++ and the teacher gave us a HW assignment and I'm stuck with one of the questions I did the IPO chart but need to code the program can some one please explain it to me or help me in any way.
    :
    : Question:
    : Builders Inc. needs a program that allows the company's salesclerk to enter both the diameter of a circle (in feet) and the price of railing material per foot. The diameter and the price may contain decimal places. The program should display both the circumference of the circle and the total price of the railing material. Use 3.141593 as the value of pi.
    :
    : I have to create a code for this program and not sure how to write it can some one help me out.
    :
    [code]
    #include //cout and cin for output and input
    using namespace ::std;

    const float PI = 3.141593f;

    int main () {

    double diameter=0.0;
    double pricePerFoot=0.0;

    // Get diameter of circle
    cout << "Please enter diameter: ";
    cin >> diameter;

    // Get price per foot here via cin...

    // Calculate circumfrence of circle (Use PI here..)
    double circumfrence=0.0;

    // Calculate total price. Total price is based off PricePerFoot
    // If circumfrence is not in feet, you may need to divide it in
    double total = circumfrence * pricePerFoot;

    // Display resaults
    cout << "

    Circumfrence: " << circumfrence << endl;
    cout << "Total price: " << pricePerFoot << endl;

    return 0;
    }[/code][blue]
    This code is not complete, but should get you started. Because this is a learning exercise via homework, I will leave the rest up to you.

    Please note, this code was not tested nor compilied, but should give you ideas on how to complete this assignment.

    If you need help, let us know.

    good luck![/blue]
  • hey there I almost completed it but my question is how do you calculate the price per foot I know its
    pricePerfoot = ?

    can you help me out there math is my weakness.
  • : hey there I almost completed it but my question is how do you calculate the price per foot I know its
    : pricePerfoot = ?
    :
    : can you help me out there math is my weakness.
    :
    [green]
    : Question:
    : Builders Inc. needs a program that allows the company's salesclerk to [b]enter both the diameter of a circle (in feet) and the price of railing material per foot.[/b] The diameter and the price may contain decimal places. The program should display both the circumference of the circle and the total price of the railing material. Use 3.141593 as the value of pi.
    [/green]
    [blue]
    Doesnt the user input the price per foot?[/blue]
    [/blue]
  • : : hey there I almost completed it but my question is how do you calculate the price per foot I know its
    : : pricePerfoot = ?
    : :
    : : can you help me out there math is my weakness.
    : :
    : [green]
    : : Question:
    : : Builders Inc. needs a program that allows the company's salesclerk to [b]enter both the diameter of a circle (in feet) and the price of railing material per foot.[/b] The diameter and the price may contain decimal places. The program should display both the circumference of the circle and the total price of the railing material. Use 3.141593 as the value of pi.
    : [/green]
    : [blue]
    : Doesnt the user input the price per foot?[/blue]
    : [/blue]
    :

  • I appreciate the help I was able to complete the assignment can I ask for you to help me with another one?

    Question:

    Your friend Joe saves pennies in a jar, which he empties every month when he goes to the bank. You areto create a program that allows him to enter the number of pennies, and then calculates and displays the number of dollars, quarters, dimes, nickels, and pennies he will recieve when he trades in the pennies at the bank.


    can you help with this last question then I have completed my work for this class.
  • : I appreciate the help I was able to complete the assignment can I ask for you to help me with another one?
    :
    : Question:
    :
    : Your friend Joe saves pennies in a jar, which he empties every month when he goes to the bank. You areto create a program that allows him to enter the number of pennies, and then calculates and displays the number of dollars, quarters, dimes, nickels, and pennies he will recieve when he trades in the pennies at the bank.
    :
    :
    : can you help with this last question then I have completed my work for this class.
    :
    [blue]
    100 pennies=1 doller
    25 pennies=1 quarter
    10 pennies=1 dime
    5 pennies=1 nickle

    Just divide the number of pennies, and compare..[/blue][code]
    const int PENNIESDOL = 100; //pennies per doller

    int iPennies=0;

    // get number of pennies va cin

    // find dollers
    int iNumDollers=0;
    while (iPennies>PENNIESDOL) {

    iNumDollers++; //...one more doller
    iPennies-=100; //100 less pennies
    }[/code][blue]
    Everything else (dimes, quarters, nickels, etc..) can use the same setup.

    Hope this helps![/blue]
  • :I don't understand I understand the value but how do you do the calculations for the program?
  • [b][red]This message was edited by MT2002 at 2007-2-5 23:26:55[/red][/b][hr]
    : :I don't understand I understand the value but how do you do the calculations for the program?
    :
    [blue]
    Their really is no calculations needed.
    [/blue][code]
    // find dollers
    int iNumDollers=0;
    while (iPennies>100) { //100 pennies in a doller

    iNumDollers++; //...one more doller
    iPennies-=100; //100 less pennies
    }

    // Because iPennies is directly modified, it is guaranteed to be < 100
    // after this loop. So iNumDollers==um... number of dollers.

    // Now count quarters...
    int iNumQuarts=0;
    while (iPennies>25) { //25 pennies in a quarter

    iNumQuarts++; //one more quarter
    iPennies-=25; //subtract the quarter from total number of pennies
    }

    //Now dimes... (iPennies guaranteed to be less then a quarter)
    int iNumDimes=0;
    while (iPennies>10) { //10 pennies in dime

    iNumDimes++;
    iPennies-=10;
    }

    //Nickels...
    int iNumNickels=0;
    while (iPennies>5) {

    iNumNickels++;
    iPennies-=5;
    }
    [/code][blue]
    In the end, iPennies contians the left over pennies (if any)
    iNumDollers=number of dollers
    iNumQuarts=number of quarters (Should never exceed 4)

    ...5 quarters and more would add 1 more doller. In the end, it shouldnt exceed 4.

    iNumDimes=number of dimes (Should never exceed 2)
    iNumNickels=number of nickels (Should never exceed 2)

    3 or more dimes would add 1 more quarter, as such 3 or more nickels wuld have added 1 more dime. Hence, these should never exceed 2.

    Pennies should not exceed 5, as that wuld be 1 nickel.
    [/blue]


  • I haven't learned looping yet so all he wants me to do is calculate the code for this exercise and its confusing me .
  • : I haven't learned looping yet so all he wants me to do is calculate the code for this exercise and its confusing me .
    :

    Without looping:
    [code]
    iNumDollars = (int) (pennies / 100)
    iRestCash = pennies % 100
    ...
    [/code]
    % is the Modulus (remainder after division) operator.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry

  • : I haven't learned looping yet so all he wants me to do is calculate
    : the code for this exercise and its confusing me .
    :

    this is one way the problem could be completed without using loops. hope this helps.

    #include

    using std::cout;
    using std::cin;
    using std::endl;

    int main()
    {
    //declare variables
    int numPennies = 0;
    int remainder = 0;
    int dollars = 0;
    int quarters = 0;
    int dimes = 0;
    int nickels = 0;
    int pennies = 0;

    //get input item from user
    cout << "Enter the number of pennies that are in the jar: ";
    cin >> numPennies;

    //calculate change bank will give Joe
    dollars = numPennies / 100;
    remainder = numPennies % 100;
    quarters = remainder / 25;
    remainder = remainder % 25;
    dimes = remainder / 10;
    remainder = remainder % 10;
    nickels = remainder / 5;
    remainder = remainder % 5;
    pennies = remainder / 1;

    //display output items
    cout << "You will receive " << dollars << " dollars, " << quarters << " quarters, " << dimes << " dimes, "
    << nickels << " nickels, and " << pennies << " pennies from the bank." << endl;

    return 0;
    } //end of main function
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories