Jun 20, 2012 at 9:36pm UTC
Hello i wrote this program but i got an error message for line 6:
#include <iostream>
using namespace std;
int main()
{
int r;
float pi=3.14159;
cout << "Type the radius.";
cin >> r;
cout << "The circumference is "; << 2*pi*r;
return 0;
}
but i get this error message:
"ComeauTest.c", line 6: warning: variable "pi" was declared but never referenced
double pi=3.13159;
How do you correct that?
thanks
Last edited on Jun 20, 2012 at 9:41pm UTC
Jun 20, 2012 at 9:39pm UTC
It is not an error it is a warning that you may ignore. As you are not going to change the value of pi I advice to declare it as
const float pi=3.13159;
I am sorry. I have not seen the semicolon after string literal "The circumference is " in statement
cout << "The circumference is "; << 2*pi*r;
You shall remove it.:)
It seems that it is a bug of the compiler. It shall issue an error instead of warning.:)
Last edited on Jun 20, 2012 at 9:45pm UTC
Jun 20, 2012 at 9:44pm UTC
Ok, now i get it... Thanks for the help!
Last edited on Jun 21, 2012 at 8:57pm UTC
Jun 20, 2012 at 9:46pm UTC
Please reread my previous message. I have updated it.
Jun 20, 2012 at 10:44pm UTC
Doppler wrote:cout << "The circumference is " ; << 2*pi*r;
This line has two statements, not 1. The first statement outputs
"The circumference is" . The second statement doesn't affect
std::cout . The second statement is an error. However, the expression
2*pi*r doesn't affect program flow, and therefore, the compiler will remove it; thus,
pi is never used, because the only expression that references
pi was optimised away.
Wazzak
Last edited on Jun 20, 2012 at 10:54pm UTC