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";
#include <iostream>
usingnamespace 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
@ 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;
#include <iostream>
usingnamespace 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;
elseif (q=='c')
{
goto loop;
break;
}
}
return 0;
}
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 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