error C2146- plz help
Hey, im making a prototype for a MUD using C++, mostly to get better at the launguge and just for fun, I recently encountered an error however
"error C2146: syntax error : missing ';' before identifier 'main'"
I tried debugging it and finding resources on the internet to help me, does anyone know what the problem is?
#include <iostream>
#include <fstream>
using namespace std;
void look()
int main()
{float name;
int HP, XP, room;
HP = 100;
XP = 0;
room = 1;
ifstream a_file (info.txt");
look()
{if (room == 1) {cout<<"This is a grassy plain\n There is 3 deer here.\n";}
else
{cout<<"Fatal error\n";} return 0; }}
cout<<"Whats your name?";
cin>> name;
cout<<"Welcome "<< name <<\n";
a_file<<" "<< name<<" ";
cout<<"You are in a grassy field\n";
return 1 } }
# 2 Re: error C2146- plz help
I tried that, when I do that I just get abunch of other errors
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(14) : error C2065: 'info' : undeclared identifier
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(14) : error C2001: newline in constant
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(14) : error C2228: left of '.txt' must have class/struct/union type
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(14) : error C2143: syntax error : missing ')' before 'string'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(19) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(28) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(28) : error C2501: 'cout' : missing storage-class or type specifiers
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(28) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(29) : error C2143: syntax error : missing ';' before '>>'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(29) : error C2501: 'cin' : missing storage-class or type specifiers
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(29) : error C2143: syntax error : missing ';' before '>>'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(30) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(30) : error C2501: 'cout' : missing storage-class or type specifiers
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(30) : error C2086: 'cout' : redefinition
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(30) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(30) : error C2017: illegal escape sequence
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(30) : error C2001: newline in constant
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(34) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(34) : error C2501: 'cout' : missing storage-class or type specifiers
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(34) : error C2086: 'cout' : redefinition
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(34) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(36) : error C2143: syntax error : missing ';' before 'return'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(36) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\Cpp1.cpp(36) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.
Cpp1.exe - 24 error(s), 0 warning(s)
# 5 Re: error C2146- plz help
OMG! WHat a messy code! :eek:
do that:
#include <iostream>
#include <fstream>
using namespace std;
float name;
int HP, XP;
ifstream a_file ("info.txt");
int room; //needs to be global
int look();
int main()
{
HP = 100;
XP = 0;
room = 1;
look();
cout<<"Whats your name?";
cin>> name;
cout<<"Welcome "<< name <<\n";
a_file<<" "<< name<<" ";
cout<<"You are in a grassy field\n";
return 1 }
int look(){
if (room == 1) {cout<<"This is a grassy plain\n There is 3 deer here.\n";}
else
{
cout<<"Fatal error\n";
return 0; //if ya returning then it has to be int look();
}
return 1;}
you should've done this using classes anyway, but have it yor way...
Radius at 2007-11-11 21:03:06 >
