LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-28-2013, 01:48 PM   #1
NothingElseMatters
LQ Newbie
 
Registered: May 2013
Posts: 1

Rep: Reputation: Disabled
C++


#include<iostream.h>
int main ()
{
int a,b,c,D;
double x1,x2;
cin>>a>>b>>c;
if (a!=0)
{
D=b^2-4*a*c;
if (D>0)
{
x1=(-b+sqrt(D) )/(2*a);
x2=(-b-sqrt(D) )/(2*a);
cout<<x1<<x2;
}
else
if (D=0)
{
x1=-b/(2*a);
cout<<"solutie dubla",x1;
}
else
cout<<"Nu are solutii reale";
}
else
cout<<"Nu este ecuatie de gr II ";
return 0;
}


EcgrII.cpp:12: error: `sqrt' was not declared in this scope

please help me ..what is wrong?
 
Old 05-28-2013, 02:09 PM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
Are you missing this?
Code:
#include <math.h>
jdk
 
Old 05-28-2013, 03:03 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 05-28-2013, 04:20 PM   #4
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Include <cmath>.
 
Old 05-28-2013, 04:29 PM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by dwhitney67 View Post
Include <cmath>.
I think cmath gives you std::sqrt, rather than sqrt in global scope.

I think that is the difference between math.h and cmath in C++

I don't mean to endorse the style of using math.h and using things like sqrt in global scope. I don't like that style. But the OP is using sqrt from global scope and thus needs sqrt in global scope.

With cmath (rather than math.h) the correct using statement could put the desired things into scope. So you can use cmath and still abuse global scope. I'm just saying the include of cmath isn't enough.
 
Old 05-28-2013, 06:27 PM   #6
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by johnsfine View Post
I'm just saying the include of cmath isn't enough.
Agreed; this is something I learned about 14 years ago. I figured the OP was referencing an up-to-date tutorial/book, but after revisiting his posted code, I realized he is not.

@ the OP -- Consider using the following:
Code:
#include <iostream>     // not iostream.h
#include <cmath>

use std::cout;
use std::endl;
use std::sqrt;

int main()
{
    ...
};
P.S. Take care in reading raw input from a user. There's no guarantee that a user will enter 3 int values.

P.S. #2 Using a 'return 0' at then end of the main() function is superfluous. C++ programs, when exiting gracefully, automatically return zero as the exit status.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration