Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 586021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:03:50+00:00 2026-05-13T15:03:50+00:00

Am working on a small problem and have spent quite a few hours trying

  • 0

Am working on a small problem and have spent quite a few hours trying to figure out what I did wrong. Using Dev++ compiler which at times has some cryptic error messages.

I tried to make the Volume calculation a function and got it to work but I have 2 small nits. Will work on error checking after I resolve this.

  1. With the function added, for some reason with dev++ now, the program does not pause (press any key to continue).

  2. Volume is coming up with blank instead of a number.

Thanks
PC

// The purpose of this program is to determine the Volume of a
// square-based pyramid after the user inputs the Area and
// the Height.
#include <iostream>
#include <iomanip>
using namespace std;
double calcvolume(double a, double h) 
{ 
    double volume;
    volume = ( a * h ) / 3; 
    return (volume);

} 

int main()
{                                 
   double area, height, volume;                    // declare variables

   cout << "Please enter the Area of the Square-based pyramid:";       // requests users input
   cin >> area;                                                        // assigns user input to area

   cout << "Please enter the Height of the Square-based pyramid:";     // requests user input
   cin >> height;    
                                                   // assigns user input to height
   cout << "Area= " << area << "\n";                                   // Prints user input for area
   cout << "Height= " << height << "\n";  
   calcvolume(area,height);     

   cout << "Volume= " << fixed << showpoint << setprecision(2) << volume << "\n";    // Prints resolution to the formula stored in volume

    system("pause"); // forces DOS window to pause to allow user to utilize program
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:03:50+00:00Added an answer on May 13, 2026 at 3:03 pm

    Your updated code looks correct, but you aren’t storing the calcvolume return value. The volume variable you declare in calcvolume is different than the one you declare in main. Each of these variables can only be referenced from within the function it is declared in.

    In order to save the volume,

    calcvolume(area,height);

    should be

    volume = calcvolume(area,height);

    This will store the value being returned from calcvolume in the volume variable in your main function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem when im working with a menu and a list
I am working on a small Java EE web application. The problem I have
I'm working on a small problem where I'm trying to show/hide a panel based
Im working on a small application to try out an idea that I have.
I have small problem with simple code. This code is working properly on x86
Just started working with android and ran into a small problem. I am have
I have a small problem using github. I mainly try to work with branches,
I have small problem. I'm trying to work on an XML file, but the
I have small concept problem. I am working on graph. Consider I have a
I am working on a small rails app and have a problem with ruby's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.