C++ help

kalessi

In Runtime
Messages
132
Location
Normal
I am having trouble with writing the area of the circle... I know this is basic but im still having issues with it... I attached instructions for reference....

Code:
#include<iostream>
using namespace std;

int main()
{
	int height;
	int width;
	int area;
	int perimeter;

	cout << "Please enter the height and width of a rectangle." << endl;
	cout << "height ->";
	cin >> height;
	cout << "Width ->";
	cin >> width;
	
	
	double pi, radius, area, circumference;
	pi = 3.14159;
	cout << "Please input the value of the radius:";
	cin >> radius;
	area = pi * (radius*radius) ;
	circumference=23 * pi * radius;

	cout<< "The area of the circle is " << area << "and the circumfernce is"
		<< circumference << endl;

		cout << "please enter "

		; area = height*width;
	perimeter = 2 * (height + width);

	cout << endl; // a blank line
	cout << "Area of the rectangle: " << area << "square units." <<
		<< "Perimeter of the rectangle:" << perimeter << "units.";
	cout << endl << endl;

	return 0;
 
Last edited by a moderator:
Assuming this is homework (judging by your last thread)...what exactly are you having issues with?

We're not going to do your homework for you - but if you have a specific question about an issue...we can help guide you to the answer but we won't give you the answer outright, otherwise you won't learn.

For one thing, I see that the formula you have for Circumference is incorrect.
 
Last edited:
Well the first error I get is where it says:
cout<< "The area of the circle is " << area << "and the circumfernce is"
<< circumference << endl;
The error is C2088 illegal for class. Could you tell me why I am getting that error?
 
So i got it to run this time...does this look ok?

Code:
#include<iostream>
using namespace std;

int main()
{
	int height;
	int width;
	int area;
	int perimeter;
	float pi;
	int radius;
	float circumference;

	cout << "Please enter the height and width of a rectangle." << endl;
	cout << "height ->";
	cin >> height;
	cout << "Width ->";
	cin >> width;
	area = height * width;
	perimeter = 2 * (height + width);
	cout << "Area of the rectangle: " << area << "square units." <<
		 "Perimeter of the rectangle:" << perimeter << "units."<<endl;
	
	pi = 3.14159;
	
	cout << "Please input the value of the radius for a circle";
	cin >> radius;

	area = pi*(radius*radius);
	circumference = 2*pi*radius;
	cout << "The area of the circle is" << area << "and the circumference is" << circumference << endl;
	system("pause");
 
Last edited by a moderator:
Please use
Code:
 tags when posting source code - it makes things easier to read. 

As far is it looking OK....does it run according to your homework?
 
Yeah looks good except for some spacing in between some words and numbers...not a big deal though i dont think...
 
Not sure if you forgot to paste it in the last block of code or what...but you're missing the "return 0;" at the end, as well as the closing brace ( } ) to close the main function.
 
Not sure if you forgot to paste it in the last block of code or what...but you're missing the "return 0;" at the end.

Modern IDEs (like Code::blocks and Visual Studio) will add the return statement at the end of main() if the programmer omits it in the source code.
Just a fun fact. ;)
 
Modern IDEs (like Code::blocks and Visual Studio) will add the return statement at the end of main() if the programmer omits it in the source code.
Just a fun fact. ;)

It's good practice to not entirely depend on an IDE ;). Especially as a beginning programmer. In the beginning, you should be doing pretty much everything yourself. Then later, once you actually understand what's going on and how things work, then you can use advanced tools/features of IDE's.

And yes, I do use Visual Studio. And when I did C++ development, i used Code::Blocks.
 
Back
Top Bottom