Need help with homework assignment!

I barely know where to begin! Can someone help me? The most I know is how to set up the program and declare variables!! Anyway, this is the question to number 1...



1. Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference and area. Use the constant value 3.14159 for π
Diameter = 2 x radius
Circumference = π * diameter
Area = π * radius2
Display the values of diameter, circumference and area using precision of 2.




So, This is what I have so, please know that I am an EXTREME beginner, so this may be incorrect;

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

int main()

{
const double pi= 3.14159;
double diameter;
double circumference;
double area;
double radius
double setprecision(2)

diameter = 2 x radius;
circumference= pi*diameter;
area= pi*(radius(pow));

cout<<fixed<<setprecision(2);
cout<<"diameter= "<<diameter<<endl;
cout<<"circumference= "<<circumference<<endl;
cout<<"area= "<<area<<endl;
cout<<"radius= "<<radius<<endl;

system ("pause");
return 0;
}
To use setprecision() you need to include #include <iomanip>

You are missing a ; after your variable radius. You also do not need to declare setprecision as a variable.

The formula for diameter is using an X instead of *.
diameter = 2 * radius;

The pow() function takes in two arguments. pow(variable, power)
area = n * (pow(radius, 2))

Never use system("pause") to keep the console open.
Read the sticky at top of beginners forum for console closing down

If you have any more questions feel free to ask.
Last edited on
Its late so I may be missing something. But you are missing a cin for your user to enter a radius. You will need the statement to be placed above your calculations.
Thanks for catching that sig, I rewrote what he was trying to do and compiled and and left that part out in my explanation.

You will need to add:
1
2
cout << "Enter the radius of a circle: ";
cin >> radius;
Topic archived. No new replies allowed.