simple pi calculating program

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 11
Reputation: FEARmike21 is an unknown quantity at this point 
Solved Threads: 0
FEARmike21 FEARmike21 is offline Offline
Newbie Poster

simple pi calculating program

 
0
  #1
Feb 22nd, 2009
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:
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main (int argc, char *argv[], char **env)
  7. {
  8.  
  9. cout << "Enter radius of circle:";
  10. double r = cin.get;
  11. double a = ( r * M_PI ) * ( r * M_PI );
  12.  
  13. cout << "Area is:" << a << "for radius of:" << r << ;
  14.  
  15. return 0;
  16.  
  17.  
  18. }
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.
Last edited by Ancient Dragon; Feb 22nd, 2009 at 5:47 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: simple pi calculating program

 
0
  #2
Feb 22nd, 2009
Code tags:


[code]
// paste code here
[/code]


  1. double r = cin.get;

http://www.cplusplus.com/reference/i...tream/get.html

If this is a function call, you need parentheses.
  1. double r = cin.get;
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 11
Reputation: FEARmike21 is an unknown quantity at this point 
Solved Threads: 0
FEARmike21 FEARmike21 is offline Offline
Newbie Poster

Re: simple pi calculating program

 
0
  #3
Feb 22nd, 2009
  1. cin.get (r);

instead of
  1. double r = cin.get;

?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: simple pi calculating program

 
0
  #4
Feb 22nd, 2009
Originally Posted by FEARmike21 View Post
  1. cin.get (r);

instead of
  1. 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 .
  1. double r;
  2. cin >> r;
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 794
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: simple pi calculating program

 
0
  #5
Feb 23rd, 2009
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
  1. get ( char* s, streamsize n );
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 147
Reputation: GDICommander is an unknown quantity at this point 
Solved Threads: 19
GDICommander's Avatar
GDICommander GDICommander is offline Offline
Junior Poster

Re: simple pi calculating program

 
0
  #6
Feb 23rd, 2009
The last << causes trouble.
  1. cout << "Area is:" << a << "for radius of:" << r << ;

Remove it.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 27
Reputation: rudasi is an unknown quantity at this point 
Solved Threads: 2
rudasi's Avatar
rudasi rudasi is offline Offline
Light Poster

Re: simple pi calculating program

 
0
  #7
Feb 23rd, 2009
Hi what I would is

  1. cout<<"Please enter the radius"<<endl; //prompt the user for an input
  2. double radius; // declare the variable which will hold the radius
  3. cin>>radius; //make the user enter the radius
  4. double area=M_PI*radius*radius; // i think you used the wrong formula
  5. cout<<"user entered: "<<radius<<endl
  6. <<"area is: "<<area;
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 27
Reputation: rudasi is an unknown quantity at this point 
Solved Threads: 2
rudasi's Avatar
rudasi rudasi is offline Offline
Light Poster

Re: simple pi calculating program

 
0
  #8
Feb 23rd, 2009
As mentioned above cin>> is already overloaded for use so its better to use it in this case.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 524 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC