#include <iostream>
usingnamespace std;
int main()
{
char again;
int radius;
float Pi = 3.14159;
do {
cout << "Hello! This simple program is designed to find the \n";
cout << "area and circumference of a circle. \n\n";
cout << "Please enter the radius of the circle: \n";
cin >> radius;
float area = radius * radius * Pi;
float circumference = 2 * Pi * radius;
cout << "The area of the circle is: " << area << endl;
cout << "The circumference of the circle is: " << circumference << endl;
cout << "\n\n Do you want to do this again? ";
} while ( again == 'y' );
}
You must add char again; at the top of the main, because it is a variable and it won't magically appear.
Then after cout << "\n\n Do you want to do this again? "; you have to write cin >> again;
#include <iostream> // This includes input and output capabilities
usingnamespace std; // Qualifies the std namespace (So you dont have to write std::cout, ect)
int main()
{
char again;
do
{
// Inside the brackets { } of the do loop we tell the program what we want it to do over and over until the condition is met.
} while (again == 'y'); // This is the condition. For do while loops it comes after and has a semi colon since it is a end of a statement.
}
Another thing to note about do while loops and while loops and their differences. Is that do while loops check the condition AFTER they run whatever is in the loop. Where as while loops check the condition BEFORE they run whatever is in the loop. That is a very important thing to keep in mind.