| | |
simple pi calculating program
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 11
Reputation:
Solved Threads: 0
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:
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.
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:
C++ Syntax (Toggle Plain Text)
#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; }
Any input would be greatly appreciated.
Last edited by Ancient Dragon; Feb 22nd, 2009 at 5:47 pm. Reason: add code tags
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
Code tags:
[code]
// paste code here
[/code]
http://www.cplusplus.com/reference/i...tream/get.html
If this is a function call, you need parentheses.
[code]
// paste code here
[/code]
C++ Syntax (Toggle Plain Text)
double r = cin.get;
http://www.cplusplus.com/reference/i...tream/get.html
If this is a function call, you need parentheses.
C++ Syntax (Toggle Plain Text)
double r = cin.get;
•
•
Join Date: Oct 2007
Posts: 11
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
cin.get (r);
instead of
C++ Syntax (Toggle Plain Text)
double r = cin.get;
?
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
•
•
•
•
C++ Syntax (Toggle Plain Text)
cin.get (r);
instead of
C++ Syntax (Toggle Plain Text)
double r = cin.get;
?
get here. Just use cin . C++ Syntax (Toggle Plain Text)
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
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
C++ Syntax (Toggle Plain Text)
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
(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
The last << causes trouble.
Remove it.
C++ Syntax (Toggle Plain Text)
cout << "Area is:" << a << "for radius of:" << r << ;
Remove it.
Hi what I would is
C++ Syntax (Toggle Plain Text)
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;
![]() |
Similar Threads
- simple c++ program (any help would be greatly appreciated) (C++)
- simple java program help (JavaScript / DHTML / AJAX)
- simple java program help.. (Java)
- Simple Fibonacci Program - What am I Doing Wrong? (Java)
- Help with calculating avrg from input file. (C++)
- Need Help with functions program (C++)
- Simple while loop in c++ (C++)
- How do I create a program using an Array ? (C++)
Other Threads in the C++ Forum
- Previous Thread: Problem with encoder and decoder. Please help!
- Next Thread: Implementing SIP with C++
Views: 524 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






