I am very new to c++ and am currently taking classes to learn the language. I am running into some errors when compiling and am not quite sure why. If anyone has any advice on where I went wrong it would help a ton! I think it is an error with not declaring a variable type. But if I am not mistaking I thought all the variables I used were declared at the very beginning of this function...
Here is the part of what I am trying to compile that is giving errors:
double sr(double z); { double x = 1; double right =.5*(x+(z/x)); double diff = abs(right - x);
while (diff > 0.001) { x = right; right = .5*(x+(z/x)); diff = abs(right - x); } return x; }
And the errors I am getting when I compile:
bgi++ -Wall -g functions.cxx -o functions.exe functions.cxx:77: error: syntax error before `{' token functions.cxx:79: error: `x' was not declared in this scope functions.cxx:79: error: `z' was not declared in this scope functions.cxx:79: error: `x' was not declared in this scope functions.cxx:80: error: use of `right' is ambiguous functions.cxx:79: error: first declared as `double right' here C:/Program Files (x86)/Colorado/cs1300/include/c++/3.3.1/bits/ios_base.h:808: error: also declared as `std::ios_base& std::right(std::ios_base&)' here functions.cxx:80: error: `x' was not declared in this scope functions.cxx:82: error: syntax error before `while' functions.cxx:85: error: ISO C++ forbids declaration of `right' with no type functions.cxx:85: error: conflicting types for `int right' functions.cxx:79: error: previous declaration as `double right' functions.cxx:85: error: `x' was not declared in this scope functions.cxx:85: error: `z' was not declared in this scope functions.cxx:85: error: `x' was not declared in this scope functions.cxx:86: error: ISO C++ forbids declaration of `diff' with no type functions.cxx:86: error: conflicting types for `int diff' functions.cxx:80: error: previous declaration as `double diff' functions.cxx:86: error: use of `right' is ambiguous functions.cxx:85: error: first declared as `int right' here C:/Program Files (x86)/Colorado/cs1300/include/c++/3.3.1/bits/ios_base.h:808: error: also declared as `std::ios_base& std::right(std::ios_base&)' here functions.cxx:86: error: `x' was not declared in this scope functions.cxx:87: error: syntax error before `}' token
ano
Question subject: Re: HELP with C++
Posted: Mon Sep 26, 2011 1:44 pm
I think problem is in the first line of code itself... It should not contain semicolon