program having some problem

I have made a program
this program asks twice to press any key to continue
please tell me how to fix it and kindly tell me if there is any other mistake in it.



#include <iostream>
using namespace std;

int main()
{
const char PI=3.1428;
double radius;
double side;
double area;
double diameter;
bool goOn=true;
while (goOn)

{
cout <<"Please enter the length of radius in inches = ";
cin >>radius;
cout <<"Please enter the length of the side of square in inches = ";
cin>>side;

area=(side*side)-(2*PI*radius);
diameter=(2*radius);

if (diameter>side)
cout<<"The length of the radius cannot exceed the half of the side of the square.\n ";
else
cout<<"The area is = "<<area<<" inch.sq"<<"\n";




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




if (q== 'q')
goOn=false;
}
system("pause");
return 0;
}
I just ran the code and it only printed "Press any key to Continue" once. There is only one system("pause") in your code so I don't know how it would be possible for it to print twice unless your compiler/IDE adds a pause at the end of programs.

Look at the line of code about 6 lines down const char PI = 3.1428;

I would use a double, and PI is actually 3.14159265.
Last edited on
is it ok to use system("pause")
and is there any problem in this program
system("pause") is heavily argued over. If you are just doing some casual programming on a windows based system, then yes system("pause") is okay. If you were a professional programmer programming software to be used by everyone then system("pause") is not alright.

Problem: Look above
ok
when i remove system("pause") it ask only once to press any key to continue
I have changed the value of PI ,thanks alot
it gives the error warning C4244: 'initializing' : conversion from 'double' to 'const char', possible loss of data
Last edited on
Change the data type of the PI constant to double
i.e
const double PI = 3.14159265;

Replace your current declaration of PI with the code above.

You don't store precision data in a character. Characters are for integer only.

btw: What IDE do you code in?
Last edited on
ok thank you !
Topic archived. No new replies allowed.