473,699 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function call misinterpreted as a variable

I have the piece of code below, and when i try compiling with the line

g++ 753075304.cpp

I get the following error message:

753075304.cpp: In function 'int main()':
753075304.cpp:2 9: error: 'plus' was not declared in this scope

I've gone over the code several times line by lin, and my eyes are
starting to bleed. It looks totally fine to me, and I'm actually
wondering whether I found a compiler bug, but more likely some weird
feature, or I'm just totally missing something. And before anyone asks,
yes it is homework, but I am trying to grade it, not do it. my version
of GCC (as reported by its man page) is 4.0.1 2005-07-11 and I am
running debian testing, kernel version 2.6.8-1-386 #1

#include <iostream>
using namespace std;
#include <cmath>
double quad(double, double, double);
double plus(double, double, double);
double neg(double, double, double);

int main()
{
double xpos;
double a;
double b;
double c;
double square;
double xneg;

cout << "This program will compute a quadratic equation\n";
cout << "Please enter a number: \n";
cin >> a;
cout << "Please enter another number: \n";
cin >> b;
cout << "Please enter a final number: \n";
cin >> c;

square = quad(a,b,c);
xneg = neg(a,b,square) ;
xpos = plus(a,b,square );

cout << "The positive function is: " << xpos << "\n";
cout << "The negative function is: " << xneg << "\n";

return 0;
}

double quad(double n1, double n2, double n3)
{
double y;
double z;
double w;
double root;

y = 4*n1*n3;
z = n2 * n2;
w = z-y;
root = sqrt(w);
return root;
}

double plus( double n1, double n2, double n3)
{
double x;

x= (-1 * n2 + n3)/(2*n1);
return x;
}

double neg(double n1, double n2, double n3)
{
double x;

x= (-1 * n2 - n3)/(2*n1);
return x;
}
Oct 3 '05
10 2077
M

Ok, to compile this code in g++ remove the function definitions and move
the function implementation to the top of the file. Also, some other
modifications below:
#include <iostream>
#include <cmath>
// After the header files...
using namespace std;

// No need for function definitions
double quad(double n1, double n2, double n3)
{
double y;
double z;
double w;
double root;

y = 4*n1*n3;
z = n2 * n2;
w = z-y;
root = sqrt(w);
return root;
}

double plus( double n1, double n2, double n3)
{
double x;

x= (-1 * n2 + n3)/(2*n1);
return x;
}

double neg(double n1, double n2, double n3)
{
double x;

x= (-1 * n2 - n3)/(2*n1);
return x;
} int main()
{
double xpos;
double a;
double b;
double c;
double square;
double xneg;

cout << "This program will compute a quadratic equation\n";
cout << "Please enter a number: \n";
cin >> a;
cout << "Please enter another number: \n";
cin >> b;
cout << "Please enter a final number: \n";
cin >> c;

square = quad(a,b,c);
xneg = neg(a,b,square) ;
xpos = plus(a,b,square );

cout << "The positive function is: " << xpos << "\n";
cout << "The negative function is: " << xneg << "\n";

return 0;
}


Regards,

Michael
Dec 30 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4963
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
3
14939
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
8
4830
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
2
7674
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
35
2448
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your time in considering this post, and for your comments. I wrote this function to simplify the task of combining strings using mixed sources. I often see the use of sprintf() which results in several lines of code, and more processing than really...
2
12439
by: exshige | last post by:
I read from some book that you can actually on any tag in the html page put a onClick or something and assign it with the sub/function name that is in the codebehind. I tried but it say name undefined. I am trying to make a rollover effect using codebehind. I have a <a> tag that onmouseover will call a sub in codebehind to change a <asp:image> image url. How come i can see a lot of "on" events of the <a> in the html side but when i...
28
4317
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
4
2127
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
12
3011
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8617
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.