Total members 11893 |It is currently Tue Nov 05, 2024 6:37 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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:
Code:
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




Author:

I think problem is in the first line of code itself... It should not contain semicolon


Author:
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : declaring variables problem
 PHP session variables problem in Firefox     -  
 Local variables vs Instance variables     -  
 Collections VS Set In Declaring     -  
 Declaring a Simple Function     -  
 PHP Variables     -  
 Casting Variables in php     -  
 Scope Variables in php     -  
 Apache Variables in php     -  
 Variables Are Assigned by Value     -  
 PHP session variables     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com