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.

9 Years
Discussion Span
Last Post by rudasi
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 );

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.