Can't get rid of leading zero

I'm doing assignment for my compsci beginners class. I keep getting a leading zero before you enter a value and I can't seem to get rid of it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	double piSign = 0.0;
	double radiusCircle = 0.0;
	double areaCircle = 0.0; 
	
	cout << "Enter a value for pi: " << piSign;
	cin >> piSign;

	cout << "Enter the radius: " << radiusCircle;
	cin >> radiusCircle;

	areaCircle = piSign * pow(radiusCircle, 2.0);
	cout << "The area of a circle with radius " << radiusCircle << " is " << areaCircle << endl;

	return 0;
} 
You may be talking about this:

cout << "Enter a value for pi: " << piSign;

That piSign was previously set to 0.0 just above this. You are printing it out right after asking for the value, just remove it and the zero won't show up.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	double piSign = 0.0;
	double radiusCircle = 0.0;
	double areaCircle = 0.0; 
	
	cout << "Enter a value for pi: ";
	cin >> piSign;

	cout << "Enter the radius: ";
	cin >> radiusCircle;

	areaCircle = piSign * pow(radiusCircle, 2.0);
	cout << "The area of a circle with radius " << radiusCircle << " is " << areaCircle << endl;

	return 0;
} 


Also since pi is a constant value (i.e. it never changes) you can declare it as such.

const double pi = 3.14159265
Last edited on
Thank you so much!!!
Topic archived. No new replies allowed.