ID:29627
 
I thought I had a nice grasp of C++, following alot of books and online tuts, but yet, when I made a simple program, I got these errors:

24 untitled1.cpp
parse error before `{'


29 untitled1.cpp
case label `'D'' not within a switch statement

29 untitled1.cpp
confused by earlier errors, bailing out

20 untitled1.cpp
for each function it appears in.)


D: Here be the source



#include <iostream.h>

//Global Variables

//Players HP
int hp=40;
int str=7;
int def=2;

//Monsters HP
int monHP=45;
int monStr=6;
int monDef=2;

//Damage
int damage=str-monDef;
int monDamage=monStr-def;

int main(){
char input;
while(hp>0){
cout<<"A monster has appeared and begins to attack! What do you do?"<<endl;
cout<<"A - Attack"<<endl<<"D - Defend"<<endl;
switch input{
case 'A':
cout<<"You attack the monster for "<<damage<<endl;
cout<<"Monster attacks you for "<<monDamage<<endl;
break;
case 'D':
cout<<"You defend against the monsters attacks!"<<endl;
cout<<"Monster weakly attacks you for "<<mondamage-=2<<endl;
break;
/* case default:
cout<<"You entered an incorrect value! A or D only!";
break; */

}
cout<<"HP remaining : "<<hp<<endl;
cout<<"Monster HP remaining : "<<monHP<<endl;
system("PAUSE");

}
return 0;
}


Sorry for not being fully commented :'[
Eh, throw in a:

using namespace std;

after the #include statement; you can't access cout without using its namespace, so you either have to explicitly use it by using std::cout in place of cout, or by implicitly using it, such as with the aforementioned using namespace std; statement.
Hiead wrote:
Eh, throw in a:

using namespace std;

after the #include statement; you can't access cout without using its namespace, so you either have to explicitly use it by using std::cout in place of cout, or by implicitly using it, such as with the aforementioned using namespace std; statement.

D: You do? I never had to do it with Dev-C++ at school @@
Oh weel. Thanks, I'll give it a shot

EDIT

It still wants to complain. Also, I forgot to give these two linker errors:

g++: c:\documents and settings\danny\desktop\programming\c++\opengl\chapter 01\lol.o: No such file or directory
g++: file path prefix `C:\DEV-C_~1\Bin\' never used

g++: c:\documents and settings\danny\desktop\programming\c++\opengl\chapter 01\lol.o: No such file or directory
g++: file path prefix `C:\DEV-C_~1\Bin\' never used


What is G++?
G++ is a C++ compiler, commonly used in unix environments, IIRC. The closest thing for Windows that I can think of is MinGW.