Console output after a while loop.

Hi, I have written a program that calculates the area of a circle from the radius that is entered by the human. Here's the thing: The program loops until a value of 0 is entered into the console. Everything is almost working as intended, but when I enter 0 into the console, the program still attempts to write the area of the circle. Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* Pseudocode:
              Ask for a radius
              while(radius != zero)
                           calculate and display the area
                           Ask for another Radius
              Display good-bye message */

#include <iostream>
#include <string>

using namespace std;

int main()
{
    const double PI = 3.14;
    double Radius;
    cout << "Circle Area calculator program!" << endl;
    while((Radius != 0) && !(Radius < 0)) {
                  cout << "Enter the radius of the circle (0 to quit) ";
                  cin >> Radius;
                  cout << "Area is " << (PI * Radius * Radius) << endl;
                  }
    cout << "Have a good day!" << endl;
    system("PAUSE");
    return 0;
}


And here's what the console output looks like if I enter 0:

1
2
3
Area is 0
Have a good day!
Press any key to continue...


How do I remove the "Area is 0" part whenever 0 is entered? Thanks in advance.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>

using namespace std;

int main()
{
    const double PI = 3.14;
    double Radius,Area;//<<<<
    cout << "Circle Area calculator program!" << endl;
    while((Radius != 0) && !(Radius < 0)) {
                  cout << "Enter the radius of the circle (0 to quit) ";
                  cin >> Radius;
                  Area=PI * Radius * Radius;//<<<<
                  if(Area!=0)
                  cout << "Area is " << (PI * Radius * Radius) << endl;
                  else//<<<<
                  break;//<<<<
                  }
    cout << "Have a good day!" << endl;
    system("PAUSE");
    return 0;
}
Neither program follows the psuedocode.
Both programs exhibit a problem at the while loop.
Radius is uninitialized the first time through the while condition.
If Radius happens to be a negative number, the loop would not execute at all.
This is why the psuedocode said to ask for a radius BEFORE the while condition.
Chriscpp's if statement is unnecessary if you follow the psuedocode.


Topic archived. No new replies allowed.