Unable to make this program

I am trying to make this program.I want it to ask the user if it he wants to quit the program or not.
Please tell me how can I do that




#include <iostream>
using namespace std;
int main()
{
double radius;
cout <<"please enter the radius =";
cin >>radius;
double side;
cout <<"please enter the side =";
cin>>side;
double area;
area=(side*side)-(2*3.1425*radius);
double diameter;
diameter=(2*radius);

if (diameter>side)
cout<<"radius is not in the range\n ";
else
cout<<"the area is = "<<area<<" inches"<<"\n";


while(true)
{
cout <<"please enter the radius =";

cout <<"please enter the side =";
int q;

cout"press Q to exit the program";
cin>>q;

if ( q=q )
break;

}



return 0;
}
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
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
int main()
{
double radius;
cout <<"please enter the radius =";
cin >>radius;
double side;
cout <<"please enter the side =";
cin>>side;
double area;
area=(side*side)-(2*3.1425*radius);
double diameter;
diameter=(2*radius);

if (diameter>side)
cout<<"radius is not in the range\n ";
else
cout<<"the area is = "<<area<<" inches"<<"\n";


while(true)
{
cout <<"please enter the radius =";

cout <<"please enter the side =";
char q;

cout << "press Q to exit the program";
cin>>q;

if ( q=='q')
break;

}



return 0;
}


here is it, you have had several mistakes...try using endl to make it prettier xP
Last edited on
@ turke Thanks turke !
I want this program to ask the user if enter c continue the program starts from
cout << "enter the radius value "
If the user enter q the program finishes without asking press any key to continue .


#include <iostream>
using namespace std;
int main()
{
double radius;
cout <<"please enter the radius =";
cin >>radius;
double side;
cout <<"please enter the side =";
cin>>side;
double area;
area=(side*side)-(2*3.1425*radius);
double diameter;
diameter=(2*radius);

if (diameter>side)
cout<<"radius is not in the range\n ";
else
cout<<"the area is = "<<area<<" inches"<<"\n";


while(true)
{

char q;

cout << "Enter Q to exit the program or Enter C to continue";
cin>>q;

if ( q=='q')
break;

}



return 0;
}
I hope you meant this =P

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
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
int main()
{
double radius;
loop:cout <<"please enter the radius =";
cin >>radius;
double side;
cout <<"please enter the side =";
cin>>side;
double area;
area=(side*side)-(2*3.1425*radius);
double diameter;
diameter=(2*radius);

if (diameter>side)
cout<<"radius is not in the range\n ";
else
cout<<"the area is = "<<area<<" inches"<<"\n";


while(true)
{

char q;

cout << "Enter Q to exit the program or Enter C to continue";
cin>>q;

if ( q=='q')
break;
else if (q=='c')
{
     goto loop;
     break;
     }
}



return 0;
}
Can you make the same program instead of using goto loop I mean by using while , do while , or for loop instead of goto loop ?
@masiht: This isn't a homework service. Turke has provided you with ample information to complete the task on your own.
Oh sry, I didn't know I can't post solved problem...
My bad =P
This is not my home question.
they are much harder and complex than this.
I was just confused in the looping.
@ turke , Thanks to you turke .your solved program helped me in understanding alot of other things.
if you wanna while loop you must make it like this...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
  int n;
  while (n!=0) {
    cout << "Enter number (0 to end): ";
    cin >> n;
    cout << "You entered: " << n << "\n";
     }
    system("PAUSE");
    return 0;
}
I am not able to compare this with what I want to do .
You just have to copy it on your program. It's not really hard to do!!
I want to make a program that asks enter Q to quit or enter C to continue the program using while or do while
If your having significant issues with this. Perhaps you should try reading some of the tutorials on this site instead of asking for pieces of code.
http://www.cplusplus.com/doc/tutorial/

If this is significantly important. I suggest you try somewhere like www.rentacoder.com where you can hire a programmer to complete your task.
Well basicly when you enter while(something) it will loop for as long as something doesn't return false...When loop finds that (something) == false it will break. So in the upper code it will run as long as you don't enter 0
Thanks guys.
Topic archived. No new replies allowed.