Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 8:08 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: HELP with C++
PostPosted: Thu Sep 22, 2011 2:10 am 

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


TOP
  
Reply with quote  
 Question subject: Re: HELP with C++
PostPosted: Mon Sep 26, 2011 1:44 pm 
I think problem is in the first line of code itself... It should not contain semicolon


TOP
  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team