Hello, I made the following code based on the following physics problem:
"A sphere of metal has a radius of 6.7 cm and a density of 9.27 g/cm^3. What's the mass of the sphere?".
The program runs error-free, except that it gives me a result (mass) of 8758.99 grams. The result using my TI 89 calculator is 11678.7 grams. I believe the TI 89 must be correct. What could be the problem?
Thanks a bunch!

#include "stdafx.h"
#include <cmath>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
	double radius, density, mass, volume, pi;
	cout<<"Enter radius: \n";
	cout<<"Enter density: \n";
         cout<<"The mass of the sphere is: "<<mass<<" grams.\n";
 	return 0;

Edited 5 Years Ago by Marcial: n/a


Integer division. 4 / 3 is 1, not 1.333. Try replacing with floating point to avoid this problem.

This question has already been answered. Start a new discussion instead.