Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

error in C++ while compiling


ghost's Avatar
0 0

I'm trying to learn c++ and as one of the project examples in the book that i'm reading i modified a few things and messed around figuring out how it reacts.. anywho with my code i get an error while compiling. Here's my source.. i should see the error but i've stared at it for 45 minutes and have got it down to 1 error (there were 3). Here's what i got

//Program 1.2
//Aqrhine Da Vinci
//May 31, 2005

#include <iostream.h>

#define TIME1  88.7     // DownHill
#define TIME2 138.05    // Slalom, 1st att.
#define TIME3 185.16    // Slalom, 2nd att.

#define NAME "P.Wiberg, NOR"
#define SE "sec." << endl

void main ()
{

	cout << endl
		 << "Program 1.2" << endl
	         << "the Olympic Games, Lillehammer, Norway" << endl
		 << "ALPINE SKIING - Combined Slalom Women" << endl
		 << "21-feb-94" << endl

		 << NAME << endl
		 << "Downhill"			    << TIME1			<< SE
		 << "slalom, 1st attempt"	<< (TIME2 - TIME1)  << SE
		 << "slalom, 2nd attempt"   << (TIME3 - TIME2)  << SE;
}

It's simple simple using the #define directive i get it entirely but there's somthing i'm missing i suppose.


ghost's Avatar
0 0

What is the error?


ghost's Avatar
0 0

Try the below. I changed #include <iostream.h> to #include <iostream>. Also, I added the line using namespace std;

Lemme know if that works.

//Aqrhine Da Vinci
//May 31, 2005

#include &lt;iostream&gt;
using namespace std;

#define TIME1 88.7 // DownHill
#define TIME2 138.05 // Slalom, 1st att.
#define TIME3 185.16 // Slalom, 2nd att.

#define NAME &quot;P.Wiberg, NOR&quot;
#define SE &quot;sec.&quot; &lt;&lt; endl

void main ()
{

cout &lt;&lt; endl
&lt;&lt; &quot;Program 1.2&quot; &lt;&lt; endl
&lt;&lt; &quot;the Olympic Games, Lillehammer, Norway&quot; &lt;&lt; endl
&lt;&lt; &quot;ALPINE SKIING - Combined Slalom Women&quot; &lt;&lt; endl
&lt;&lt; &quot;21-feb-94&quot; &lt;&lt; endl

&lt;&lt; NAME &lt;&lt; endl
&lt;&lt; &quot;Downhill&quot; &lt;&lt; TIME1 &lt;&lt; SE
&lt;&lt; &quot;slalom, 1st attempt&quot; &lt;&lt; (TIME2 - TIME1) &lt;&lt; SE
&lt;&lt; &quot;slalom, 2nd attempt&quot; &lt;&lt; (TIME3 - TIME2) &lt;&lt; SE;
}```

ghost's Avatar
0 0

––––––––––Configuration: Cpp1 - Win32 Debug–––––––––– Compiling… Cpp1.cpp C:\Documents and Settings\Tommy Waddell\Cpp1.cpp(19) : error C2143: syntax error : missing ';' before '<<' Cpp2.cpp Error executing cl.exe.

Cpp1.exe - 1 error(s), 0 warning(s)

and the change to <iostream> and the extra line didn't help


ghost's Avatar
0 0

hmm I didn't have that problem. Try putting all the cout stuff onto one line. What compiler are you using?


ghost's Avatar
0 0

microsoft visual c++


ghost's Avatar
0 0

figured it out.. thanks for your help.. i'm not sure what i did but i just tried it a while later (after restart) and it worked.


ghost's Avatar
0 0

What does this error mean?

––––––––––Configuration: Cpp1 - Win32 Debug–––––––––– Compiling… Cpp1.cpp C:\Documents and Settings\Tommy Waddell\My Documents\c++\Cpp1.cpp(72) : error C2086: 'x' : redefinition Error executing cl.exe.

Cpp1.exe - 1 error(s), 0 warning(s)

I get it from this section here:

const int Max = +32767;
	const int Min = -(Max+1);
		int x;

	x = Max;
	
	cout &lt;&lt; x &lt;&lt; endl;

	x = Max + 1;
	cout &lt;&lt; x &lt;&lt; endl;

	x = Max + 2;
	cout &lt;&lt; x &lt;&lt; endl;

	x = Min;
	cout &lt;&lt; x &lt;&lt; endl;

	x = Min - 1;
	cout &lt;&lt; x &lt;&lt; endl;

	x = Min - 2;
	cout &lt;&lt; x &lt;&lt; endl;

sorry.. figured it out seems that the problem wasn't that i redefined the variable "x" but that i accidently declared it a variable twice. once earlier in the code then again where i showed it. works smoothly now.. nothin quite like trial and error