How can I do this?

Hi everybody,
I'm new to this forum and I don't really know to much from c programming.
So,I have this code below :

#include<iostream>
#include<cmath>
#include <string>
using namespace std;
int main(void)
{
float r;
float P;
float S;
string exit;
cout << "Give the radius value to find the perimeter and the surface of the circle!: " <<endl<<endl;
cin >>r;
P = 6.28 * r;
cout << "The Perimeter is : " << P <<endl<< endl;
S = 3.14 * r * r;
cout << "The surface is : " << S << endl << endl <<endl;
cout << "Type exit and press ENTER to exit the program" <<endl;
getline (cin, exit) >> exit;
exit;
return 0;
}

It's nothing wrong with it.I just want to know how can I make the program to repeat the procedure so it asks again the user to put a value for the radius and find the P and S again.I would really appricioate any help.
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
27
28
29
30
#include<iostream>
#include<cmath>
#include <string>
using namespace std;
int main(void)
{
	float r;
	float P;
	float S;
	string exit;
	while(true)
	{
		cout << "Give the radius value to find the perimeter and the surface of the circle!: " <<endl<<endl;
		cin >>r;
		P = 6.28 * r;
		cout << "The Perimeter is : " << P <<endl<< endl;
		S = 3.14 * r * r;
		cout << "The surface is : " << S << endl << endl <<endl;
		cout << "Type exit and press ENTER to exit the program" <<endl;
		getline (cin, exit) >> exit;
		exit;

		char choice;
		std::cout << "More (y/n): ";
		std::cin >> choice;
		if(choice != 'y')
			break;
	}
	return 0;
}


see if this makes sense to you.

Edit: Try using code tags, right side <>
Last edited on
Use a loop. you can read about loops http://cplusplus.com/doc/tutorial/control/.
Topic archived. No new replies allowed.