CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Oct 2002
    Posts
    30

    writing functions

    I have to write a program that finds the unit price for a pizza. Input consists of price and size of pizza. I'm a beginner on writing functions.

    Use functions to:
    1. get input from user
    2. calculate price per square inch
    3. print results

    How do i square radius? i tried square(radius) but it won't work.

    Thanks


    // This program finds the price per square inch of a pizza when size and price is input by the user

    #include <iostream.h>
    #include <math.h>

    void area ();
    // prototype for area function
    void input (float &size, float &price);
    // prototype for input function

    void print_results (float price_per_sq_inch);
    // prototype for print_results function

    float price, size, wait;
    // stores price and size of pizza
    float price_per_sq_inch;
    // used to calculate price per square inch

    main() // main function

    {

    input (size, price); // calls input function
    area (); // calls area function
    print_results (price_per_sq_inch); // calls print_results function

    cin >> wait;
    return 0;
    }


    void input (float &size, float &price)
    // input function
    {
    cout << "What is the size of the pizza (diameter)? ";
    // asks user to input size of pizza
    cin >> size;
    // stores size

    cout << "What is the price of the pizza? ";
    // asks user for price of pizza
    cin >> price;
    // stores price
    }


    void area () // area function
    {
    float radius;

    // radius is declared as float

    const float PI = 3.14159;
    // declares PI as a floating constant

    radius = size/2;


    price_per_sq_inch = (PI * square(radius)/price); // **THIS LINE**


    // calculates price per square inch
    }

    void print_results (float price_per_sq_inch)
    // print_results function

    {
    // outputs results
    cout << "The price per square inch for a " << size << " inch pizza is $" << price_per_sq_inch;
    }
    Last edited by gurlygurlz; February 5th, 2003 at 09:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured