can someone help

Discussion in 'OT Technology' started by Heather, Jun 22, 2004.

1. HeatherGuest

My friend has this program due tomorrow & she can't figure out what's wrong. These stupid 0's keep popping up before & after her output & I don't know much on this other then what she telling me to explain on here. Here's her program if anyone can figure it out..that'd be awesome!

//##########################################################
//#
//# Kim
//# CSCI 151 Summer 2004
//# Dev C++ 4.9.8.9
//#
//# This program will ask the user for the length
//# of the side of a cube, and in result will calculate
//# how the largest sphere will fit in it.
//#
//##########################################################

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;

//Declare named constant for PI

const double PI = 3.1415926;

int main()
{

//Declare variables
double side = 0.0;
double sphere_volume = 0.0;
double cube_volume = 0.0;
double sphere_sa = 0.0;
double cube_sa = 0.0;
double diameter = 0.0;
double volume_between = 0.0;
double fixed = 0.0;
double showpoint = 0.0;
double left = 0.0;
double right = 0.0;

//Get input from user

cout<<"Please enter the length of the side of the cube: ";
cin>>side;

//Calculate stuff
cube_volume = pow(side, 3);
cube_sa = 6.0 * pow(side, 2);
sphere_volume = 4.0/3.0 * PI * pow(radius, 3);
sphere_sa = 4.0 * PI * pow(radius, 2);
diameter = side;
volume_between = cube_volume - sphere_volume;

//Output Section
cout<<fixed<<showpoint<<setprecision(3);
cout<<left<<setw(24)<<"Radius of the largest sphere that could fit in the cube: "<<right<<setw(12)<<radius<<endl;
cout<<left<<setw(24)<<"Volume of the cube: "<<right<<setw(12)<<cube_volume<<endl;
cout<<left<<setw(24)<<"Surface area of the cube: "<<right<<setw(12)<<cube_sa<<endl;
cout<<left<<setw(24)<<"Volume of the largest sphere that could fit in the cube: "<<right<<setw(12)<<sphere_volume<<endl;
cout<<left<<setw(24)<<"Surface area of the largest sphere that could fit in the cube: "<<right<<setw(12)<<sphere_sa<<endl;
cout<<left<<setw(24)<<"Volume of the space in between the cube and the sphere: "<<right<<setw(12)<<volume_between<<endl;

system ("pause");

return 0;

}

2. JumpemOT Supporter

Joined:
Oct 9, 2002
Messages:
37,084
2,692
I don't see the problem off hand. I don't have a C++ compiler handy either.

3. JumpemOT Supporter

Joined:
Oct 9, 2002
Messages:
37,084
2,692
I think it's because "fixed", "showpoint", "left", and "right" are initialized to 0.0. She never assigns them different values (something other than 0.0). Then she displays them to the screen. Since they are 0.0 she is seeing "0.0" before and after her real output.

4. skinjobActive Member

Joined:
Jan 6, 2001
Messages:
2,290
0
Location:
Aztlán
Post a sample of the output so we can see what the problem is.

5. skinjobActive Member

Joined:
Jan 6, 2001
Messages:
2,290
0
Location:
Aztlán
This is part of the problem. fixed, showpoint, left and right are iostream manipulators that are provided if you #include <ios>. Get rid of the variables for fixed, showpoint, etc. and #include <ios> and see if that helps.

Joined:
Jul 1, 2003
Messages:
7,328