error in C++ while compiling
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.
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 <iostream>
using namespace std;
#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;
}```
––––––––––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
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 << x << endl;
x = Max + 1;
cout << x << endl;
x = Max + 2;
cout << x << endl;
x = Min;
cout << x << endl;
x = Min - 1;
cout << x << endl;
x = Min - 2;
cout << x << 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