HELP

closed account (ENhkSL3A)
I have errors saying identifier "pi" is undefined. I also get this for radius height and others. Can someone tell me what I'm missing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>


using namespace std;

int main()
{
        cout << "Katie Stevers" << endl;
        cout << "Program 2" << endl;
        cout << "September 11, 2016" << endl;
        cout << "\t\t" << endl;
        cout << "\t\t" << endl;
        // volume, radius, height, surface area, circumference;
        pi = 3.141592653589793238462643383279502884197169399375;
        cout << "Please input the value of the radius:   " << endl;
        cin >> radius;
        cout << "Please input the value of the height:   " << endl;
        cin >> height;
        circumference = 2 * pi * radius;
        surface area = (2 * pi * (radius * radius)) + (2 * pi * radius * height);
        volume = pi * (radius * radius) * height;
        cout << "The circumference of the cylinder is " << circumference << "." << endl;
        cout << "The surface area of the cylinder is " << surface area << "." << endl;
        cout << "The volume of the circle is " << volume << "." << endl;
}
You miss a type of pi. You MUST putint pi=....
closed account (ENhkSL3A)
I'm still getting the errors. I added int to them :/
closed account (ENhkSL3A)
This is what you ment right?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main()
{
	cout << "Katie Stevers" << endl;
	cout << "Program 2" << endl;
	cout << "September 11, 2016" << endl;
	cout << "\t\t" << endl;
	cout << "\t\t" << endl;
	int pi = 3.141592653589793238462643383279502884197169399375;
	cout << "Please input the value of the radius:   " << endl;
	cin >> radius;
	cout << "Please input the value of the height:   " << endl;
	cin >> height;
	int circumference = 2 * pi * radius;
	int surface area = (2 * pi * (radius * radius)) + (2 * pi * radius * height);
	int volume = pi * (radius * radius) * height;
	cout << "The circumference of the cylinder is " << circumference << "." << endl;
	cout << "The surface area of the cylinder is " << surface area << "." << endl;
	cout << "The volume of the circle is " << volume << "." << endl;
}

Last edited on
closed account (ENhkSL3A)
Now it is only saying it for height and radius! GAhhhh! What do I do?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
	cout << "Katie Stevers" << endl;
	cout << "Program 2" << endl;
	cout << "September 11, 2016" << endl;
	cout << "\t\t" << endl;
	cout << "\t\t" << endl;
	int pi = 3.141592653589793238462643383279502884197169399375;
	cout << "Please input the value of the radius:   " << endl;
	cin >> radius;
	cout << "Please input the value of the height:   " << endl;
	cin >> height;
	int circumference = 2 * pi * radius;
	int surfacearea = (2 * pi * (radius * radius)) + (2 * pi * radius * height);
	int volume = pi * (radius * radius) * height;
	cout << "The circumference of the cylinder is " << circumference << "." << endl;
	cout << "The surface area of the cylinder is " <<  surfacearea << "." << endl;
	cout << "The volume of the circle is " << volume << "." << endl;
}
Hi kns2872.
One of the most common mistakes that programmers do, is forgetting to define the variables.
I mean for example
1
2
3
4
5
6
int age;
float height;
double pi;
.
.
.


===============================================================
The answer of your problem:
you must declare variables before using them.
In line 14,19,20,21: Replace int with double
if you use int for declaring variables witch have decimal part, the decimal part will be deleted entirely.

add this code to your program(its better to add between lines 8 and 9)
double height, radius;



Important:
Go to the http://www.cplusplus.com/doc/tutorial/variables/
Last edited on
closed account (ENhkSL3A)
Thanks so much! :)
Topic archived. No new replies allowed.