Hi, I just started my C++ class a couple weeks ago and I am stuck and having a really diffcult time understanding which commands to use in my programs. I don't even know where to look to get a list.

Anyways, basically what we have to make our program do is take an imput from the user asking "Enter radius of circle:" and with that radius calculate and output the area on the screen and reiterate what the user typed in.

Here is my source code:

#include <iostream>
#include <cmath>

using namespace std;

int main (int argc, char *argv[], char **env)
{

cout << "Enter radius of circle:";
double r = cin.get;
double a = ( r * M_PI ) * ( r * M_PI );

cout << "Area is:" << a << "for radius of:" <<  r << ;

return 0;


}

I am getting all sorts of errors and I think im on the right track I am just unsure of how exactly to type it out.

Any input would be greatly appreciated.

Recommended Answers

All 7 Replies

cin.get (r);

instead of

double r = cin.get;

?

cin.get (r);

instead of

double r = cin.get;

?

When in doubt, try it and find out for sure, which I imagine you have. The link I posted has specs and examples. None of them take a double as a paremeter. I don't see any reason for you to use get here. Just use cin .

double r;
cin >> r;

I agree with, VernonDozier.
cin>> is already overloaded for you to input the right thing.
cin.get is a unformated input function. It does not format the input accordingly. It is just used for char
heres the prototype

get ( char* s, streamsize n );

The last << causes trouble.

cout << "Area is:" << a << "for radius of:" <<  r << ;

Remove it.

Hi what I would is

cout<<"Please enter the radius"<<endl; //prompt the user for an input
double radius; // declare the variable which will hold the radius
cin>>radius; //make the user enter the radius
double area=M_PI*radius*radius; // i think you used the wrong formula
cout<<"user entered: "<<radius<<endl
       <<"area is: "<<area;

As mentioned above cin>> is already overloaded for use so its better to use it in this case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.