My first program

Hi. I'm new to programming, i started reading and playing around with it like last night so i'm a big noob. I use Codeblocks for all my programming needs.

I was just creating my first program all by myself without any help from other programs or people. What the program does is it asks for any radius of a circle and then tells you what the circumference of the circle is. Any comments, good or bad, are welcomed. Sorry about my english. I'm from Iceland.


#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main ()
{
string mystr;
int r;

cout<<"Enter radius of circle: ";
getline (cin,mystr);
stringstream(mystr) >> r;
cout<< "The circumference of the circle is:" << r*2*3.141592;
cout<<"\n";
cin.get();
}


Thank you, MightyBearman.
Last edited on
Ah, well well well, not bad at all, especially considering that this your first program. One change you could make is to have r as a double precision floating-point integer, just to have some more fun with the radii. ;)

One thing though (I'm a harsh critic, I know...), you forgot a return 0;. Furthermore, you can rewrite this program without the stringstream so as to use less memory (I know why you have it, though).

Excellent work, otherwise!

-Albatross
Last edited on
return 0; is not necessary for the main function, as it will implicitly return 0 when it reaches the end.
And I have to agree, it's pretty good for a first program.
Topic archived. No new replies allowed.