Like Tree1Likes
  • 1 Post By Khabz

ahh need massive help with this C++ program dealing with calculation of volume/area

This is a discussion on ahh need massive help with this C++ program dealing with calculation of volume/area within the C++ Programming forums, part of the General Programming Boards category; Write a program that calculates area/volume of various shapes. 1st call function w/ prototype: void showMenu(int &); which displays menu ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    ahh need massive help with this C++ program dealing with calculation of volume/area

    Write a program that calculates area/volume of various shapes.
    1st call function w/ prototype: void showMenu(int &); which displays menu

    this is what the output should be:
    Name:  photo(56).JPG
Views: 673
Size:  145.8 KB

    this is what i have so far... yeah, fairly lost

    // This program is designed to allow the user to calculate the area and volume of various shapes.

    #include <iostream>
    #include <iomanip>

    using namespace std;

    void showMenu (int &);
    double area (double length, double width);
    double area (double radius);
    double volume (double length, double width, double height);
    double volume (double radius);

    int main()
    {
    int selection;

    double length;
    double width;
    double height;
    double radius;

    cout << fixed << showpoint << setprecision(2);

    cout << "1. Calculate the area of a rectangle" << endl;
    cout << "2. Calculate the area of a circle" << endl;
    cout << "3. Calculate the volume of a box" << endl;
    cout << "4. Calculate the volume of a sphere" << endl;
    cout << "5. Quit" << endl;
    cin >> "Please select 1-5: " >> selection;
    cout << endl;

  2. #2
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    What is exacly your doubt?

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    2
    kinda dunno where to go from here; i'll try to make more advances in the program and find my doubts

  4. #4
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    I'll start by pointing out this obvious error:

    Code:
    cin >> "Please select 1-5: " >> selection;
    This cannot happen. Cin is supposed to 'read' the user's input. Cout is what the console prints so I'd change it to this.

    Code:
    cout<<"Please select 1-5";
    cin>>selection;
    As for the following code:

    Code:
    void showMenu (int &);
    That's a function prototype.
    When you define a function after your main code, then you must have a prototype before the main code so it can know it has been defined later on.
    It should have the following structure:

    Code:
    void showMenu(int &)   //<--- Prototype
    
    int main()
    {
          showMenu(int &)
          (.........);
    }
    
    void showMenu(int &)   //<-- Your function defined
    {
        (.....);
    }
    OR

    Code:
    void showMenu(int &)  //<-- The function has been defined before main so prototype is not required
    {
        (.......);
    }
    
    int main()
    {
         showMenu(int &);
         (...........);
    }
    If I was you I'd make a function for each option. One to compute a rectangle area, another for a circle area etc and then call each one of them depending on the user input (1-5).
    Last edited by Khabz; 03-14-2013 at 07:56 PM.
    laserlight likes this.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Btw, the function call is wrong.
    Instead of

    showMenu(int &);

    do

    showMenu(your_favorite_int_variable_here);
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with Card Dealing Program
    By Izzy123 in forum C++ Programming
    Replies: 5
    Last Post: 03-28-2011, 01:39 PM
  2. USB Problem : Volume to Volume copy by sector
    By anuj7anuj in forum C++ Programming
    Replies: 2
    Last Post: 01-27-2011, 07:47 AM
  3. Replies: 44
    Last Post: 03-19-2010, 04:06 PM
  4. Randomizing dealing program C
    By BSmith4740 in forum C Programming
    Replies: 2
    Last Post: 08-04-2008, 01:42 PM
  5. Card Dealing program help
    By Randoon in forum C Programming
    Replies: 1
    Last Post: 11-13-2002, 07:27 PM

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