am just a beginner and an getting the compiling error like:(warning: no newline at end of file) anyone who could help me out?

#include <iostream>
#include <cmath>
using namespace std;

int main(){
int a;
int b; 
int c; 
double p;
double x1;
double x2;
cout<<"bitte lesen sie vier nummern ein:";
cin>>a>>b>>c;
	p=(b*b)-(4*a*c);
	if(p>0){
		x1=((-b) + sqrt(p))/2*a;
		x2=((-b) - sqrt(p))/2*a;
	if(x1==x2)
cout<<"value of x = "<<x2;
	else
cout<<"x1 = "<<x1;cout<<"x2 = "<<x2;
		}
	
	else{
		p=(-1)*p;
		x1=((-b) + sqrt(p))/2*a;
		x2=((-b) + sqrt(p))/2*a;
	if(x1==x2)
cout<<"value of x = "<<x2;
	else
	cout<<"x1 = "<<x1;cout<<"x2 = "<<x2;
		}
return 0;
}

Recommended Answers

All 8 Replies

some compilers complain if the last line of the file is not a newline. In the editor go to the last line and hit <Enter>. That should fix that warning.

Which compiler are you using? Strange error :O

On line 31, place the second 'cout' statement on the next line.
or you could write it like this instead:

cout << "x1 = " << x1 << "x2 = " << x2;

regards
nm

Also note that a warning is different from an error. Code will compile and run with 100 warnings but it wont compile or run with even a single error. Warnings are little helpful hints given by the compiler. The no new line at the end of file is generally given by unix based compilers. Windows based compilers, at least the ones that i have seen, generally don't complain about that.

<<"bitte lesen sie vier nummern ein

a,b,c and what is the fourth number?

Chapter 2 of the C++ Standard defines C++ preprocessor functionality:

...If a source file that is not empty does not end in a new-line character, or ends in a new-line character immediately preceded by a backslash character before any such splicing takes place, the behavior is undefined.

It's the other story why...
Source files w/o trailing new-line character are in fact ill-formed. It's a standard de-facto not only for C++ compilers.

btw Line 19 what's the value of x2? If you know it I will know it too.(should be -b/2a)
Lines 18 and 19 are the same as lines28 and 29.Lines 26 and 27 are the same (a plus should be a minus) and now I notice! The whole if-statement is a mess! Th cause of your problem?

Also note that a warning is different from an error. Code will compile and run with 100 warnings but it wont compile or run with even a single error. Warnings are little helpful hints given by the compiler. .

Not necessarily true -- many, if not most, warnings that people get are really errors, depending on the warning level you set with your compiler. Your goal should be to get 0 warnings and 0 errors. The more you clean those things up and avoid the warnings the easier it is for you to fix the real problems.

The latest Microsoft compiler has a nasty habbit of declaring many standard C functions depriciated with they aren't. I just use the pragma to turn off those warnings.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.