You are viewing our Forum Archives. To view or take place in current topics click here.
Dev c++ Please Help Me Im a Begginer +rep
Posted:

Dev c++ Please Help Me Im a Begginer +repPosted:

MeatMaster69
  • New Member
Status: Offline
Joined: May 31, 201410Year Member
Posts: 8
Reputation Power: 0
Status: Offline
Joined: May 31, 201410Year Member
Posts: 8
Reputation Power: 0
I am very new to programing and I am in computer programing and need help with my code. we use Dev c++ and I need to make a program that will ask for the radius of a ball and what kind of ball it is then do some math and get an output. Here is what I have so far..

#include <iostream>
#include <string>
#include <cmath>

#include <iostream>
using namespace std;

#define PI 3.14159265

int main()
{
//Dim variables
int radius1, radius2, ball1, ball2;

// Display message heading

cout << "Find the surface area and volume of a ball! ";

//Ask for sphere data (name and radius)
cout << "What kind of ball is it?";

cin >> ball1;

cout << "What is the radius in inches?";

cin >> radius1;

cout << "What is the seccond ball?";

cin >> ball2;

cout << "What is the radius of it?";

cin >> radius2;

//calculate sphere1 volume and surface area
SA_Sphere1 = 4.0 * PI * pow(radius1,2);
Vol_Sphere1 = 4.0/3.0 * PI * pow(radius1,3);

//calculate sphere2 volume and surface area
SA_Sphere2 = 4.0 * PI * pow(radius2,2);
Vol_Sphere2 = 4.0/3.0 * PI * pow(radius2,3);

//Report data to screen


return 0;
}


The instructor gave us some of the basics.. and when I try to run it, the line that starts SA_sphere1 shows an error
#2. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
I'm assuming the problem is you haven't declare SA_Sphere as a variable.


//calculate sphere1 volume and surface area
float SA_Sphere1 = 4.0 * PI * pow(radius1,2);
float Vol_Sphere1 = 4.0/3.0 * PI * pow(radius1,3);

//calculate sphere2 volume and surface area
float SA_Sphere2 = 4.0 * PI * pow(radius2,2);
float Vol_Sphere2 = 4.0/3.0 * PI * pow(radius2,3);


After declaring your floats, I don't see why it shouldn't store the value correctly
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.