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;
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 constchar PI = 3.1428;
I would use a double, and PI is actually 3.14159265.
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.
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