0
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
//Declares a variable named name that holds text.
string name;
//Declares variables named height and radius that hold whole numbers.
int height, radius;
//Declares a variable named volume that holds double precision real numbers.
double volume;
//Declare a constant variable for PI
const double PI = 3.1415;
//Declare input file
ifstream inFile;
//open file
inFile.open("input4.txt"); 
//Prompts the user "May I get your full name please?: ".
cout << "May I get your full name please?: " << endl;
//Reads the value from the keyboard and stores it in name.
getline( cin, name);
//Prompts the user "Thanks ", name, " , now enter height and radius of the cone please: ".
cout << "Thanks " << name << ", now enter height and radius of the cone please: " << endl;
//Reads the values from the keyboard and stores them in height and radius respectively.
cin >> height;
cin >> radius;
//Calculates the volume using the formula volume = 1.0/3 x 3.1415 x radius x radius x height 
volume = 1.0/3 * PI * radius * radius * height;
//Rounds the volume to the nearest tenths (one decimal digit) and reassigns it to volume.
volume = static_cast<double>(static_cast<int>((volume * 10.0) + 0.5))/10.0;
//Print final message
cout << "Ok " << name << " the cone's volume is " << volume << endl;
inFile.close();
return 0;
}

Once I press enter to get my volume the debug lab exits before I can get the answer. I have only been able to see my answer by recording the screen and playing it back. Any help is welcome. Thank you.

Nora
  • 11
  • 1
  • 9

1 Answers1

1

Replace

volume = 1/3 * PI * radius * radius * height;

with

volume = 1.0/3 * PI * radius * radius * height;

Division of two integers results in an integer result. 1/3 = 0 remainder 1, so your entire expression is set to 0. Changing one or both operands to floating point will result in a floating point result.

owacoder
  • 4,815
  • 20
  • 47